test_stillimage.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* display single iframes as stillimages
  2. * iframes can be created with the 'convert' tool from imagemagick
  3. * and mpeg2encode from ftp.mpeg.org, and must have a supported
  4. * size, e.g. 702x576:
  5. * $ convert -sample 702x576\! test.jpg test.mpg
  6. *
  7. * or more advanced using netpbm and mpeg2enc (not mpeg2encode) :
  8. * $ cat image.jpg | jpegtopnm | pnmscale -xsize=704 -ysize=576 |\
  9. * ppmntsc --pal | ppmtoy4m -F 25:1 -A 4:3 -S 420mpeg2 |\
  10. * mpeg2enc -f 7 -T 90 -F 3 -np -a 2 -o "image.mpg"
  11. *
  12. */
  13. #include <sys/ioctl.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <fcntl.h>
  20. #include <time.h>
  21. #include <unistd.h>
  22. #include <linux/types.h>
  23. #include <linux/dvb/video.h>
  24. static const char *usage_string = "\n\t"
  25. "usage: %s <still.mpg> [still.mpg ...]\n"
  26. "\n\t"
  27. "to use another videodev than the first, set the environment variable VIDEODEV\n\t"
  28. "e.g.[user@linux]$ export VIDEODEV=\"/dev/dvb/adapter1/video1\".\n\t"
  29. "to display the image <n> seconds, instead of 10, set the variable SSTIME\n\t"
  30. "e.g. [user@linux]$ export SSTIME=\"60\" to display the still for 1 minute.\n\t"
  31. "this options can be set in the same line as the %s command:\n\t"
  32. "e.g. $ SSTIME=25 VIDEODEV=/dev/dvb/adapter1/video1 %s ...\n";
  33. int main (int argc, char **argv)
  34. {
  35. int fd;
  36. int filefd;
  37. struct stat st;
  38. struct video_still_picture sp;
  39. char *videodev = "/dev/dvb/adapter0/video0";
  40. char *env_sstime;
  41. int i = 1;
  42. int tsec = 10;
  43. if (argc < 2) {
  44. fprintf (stderr, usage_string, argv[0],argv[0],argv[0]);
  45. return -1;
  46. }
  47. if (getenv ("VIDEODEV"))
  48. videodev = getenv("VIDEODEV");
  49. if (getenv ("SSTIME")) {
  50. env_sstime = getenv("SSTIME");
  51. tsec = atoi(env_sstime);
  52. }
  53. if ((fd = open(videodev, O_RDWR)) < 0) {
  54. perror(videodev);
  55. return -1;
  56. }
  57. next_pic:
  58. printf("I-frame : '%s'\n", argv[i]);
  59. if ((filefd = open(argv[i], O_RDONLY)) < 0) {
  60. perror(argv[i]);
  61. return -1;
  62. }
  63. fstat(filefd, &st);
  64. sp.iFrame = (char *) malloc (st.st_size);
  65. sp.size = st.st_size;
  66. printf("I-frame size: %d\n", sp.size);
  67. if (!sp.iFrame) {
  68. fprintf (stderr, "No memory for I-Frame\n");
  69. return -1;
  70. }
  71. printf ("read: %d bytes\n", (int) read(filefd, sp.iFrame, sp.size));
  72. close(filefd);
  73. if ((ioctl(fd, VIDEO_STILLPICTURE, &sp) < 0)) {
  74. perror("ioctl VIDEO_STILLPICTURE");
  75. return -1;
  76. }
  77. free(sp.iFrame);
  78. printf("Display image %d seconds ...\n",tsec);
  79. sleep(tsec);
  80. printf("Done.\n");
  81. if (argc > ++i)
  82. goto next_pic;
  83. return 0;
  84. }