
Recherche avancée
Médias (1)
-
The Great Big Beautiful Tomorrow
28 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Texte
Autres articles (15)
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Supporting all media types
13 avril 2011, parUnlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)
-
Contribute to a better visual interface
13 avril 2011MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community.
Sur d’autres sites (5923)
-
ffmpeg : single frame from video is highly overexposed image
9 avril 2021, par mcgregor94086I am using ffmpeg on a Raspberry Pi 400, attached to a camera array to capture one image from each camera.


Most images generated are highly overexposed and washed out. I am trying to understand which command line options I should set to prevent this over exposure.



Are there options I need to set for the camera to automatically set the right exposure, or some way to set the length of an exposure as opposed to just a "frame" ?


Also, each image is taking about 3 to 4 seconds to capture. I just want to capture the first possible frame and that's it. Is there a set of options which would capture the image is less time ?


/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video0 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam00.jpg
Input #0, video4linux2,v4l2, from '/dev/video0':
 Duration: N/A, start: 672949.710856, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x184adb0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam00.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=1.0 q=3.7 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.39x 
video:37kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video0 image in: 3 seconds
linux_capture_photo_and_return_image_path( /dev/video0 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 1 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam00.jpg
1 /dev/video0: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam00.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video2 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam02.jpg
Input #0, video4linux2,v4l2, from '/dev/video2':
 Duration: N/A, start: 672958.327329, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x1d27db0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam02.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.9 q=8.6 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.374x 
video:136kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video2 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video2 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 2 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam02.jpg
2 /dev/video2: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam02.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video4 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam04.jpg
Input #0, video4linux2,v4l2, from '/dev/video4':
 Duration: N/A, start: 672963.021864, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x10bedb0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam04.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=1.0 q=3.7 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.389x 
video:42kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video4 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video4 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 3 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam04.jpg
3 /dev/video4: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam04.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video6 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam06.jpg
Input #0, video4linux2,v4l2, from '/dev/video6':
 Duration: N/A, start: 672967.663385, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x24e4db0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam06.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.9 q=8.2 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.352x 
video:126kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video6 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video6 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 4 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam06.jpg
4 /dev/video6: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam06.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video8 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam08.jpg
Input #0, video4linux2,v4l2, from '/dev/video8':
 Duration: N/A, start: 672972.189025, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x13fadb0] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam08.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.9 q=9.1 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.352x 
video:154kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video8 image in: 3 seconds
linux_capture_photo_and_return_image_path( /dev/video8 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 5 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam08.jpg
5 /dev/video8: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam08.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video17 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam17.jpg
Input #0, video4linux2,v4l2, from '/dev/video17':
 Duration: N/A, start: 672976.730667, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0xae6e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam17.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.9 q=8.7 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.353x 
video:164kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video17 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video17 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 6 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam17.jpg
6 /dev/video17: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam17.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video19 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam19.jpg
Input #0, video4linux2,v4l2, from '/dev/video19':
 Duration: N/A, start: 672981.425451, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x15a7e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam19.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=1.0 q=3.2 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.391x 
video:40kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video19 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video19 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 7 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam19.jpg
7 /dev/video19: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam19.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video21 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam21.jpg
Input #0, video4linux2,v4l2, from '/dev/video21':
 Duration: N/A, start: 672986.050603, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x1722e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam21.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=1.0 q=7.8 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.388x 
video:119kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video21 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video21 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 8 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam21.jpg
8 /dev/video21: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam21.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video23 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam23.jpg
Input #0, video4linux2,v4l2, from '/dev/video23':
 Duration: N/A, start: 672990.712888, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x19f4e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam23.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=1.0 q=3.4 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.389x 
video:42kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video23 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video23 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 9 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam23.jpg
9 /dev/video23: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam23.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video25 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam25.jpg
Input #0, video4linux2,v4l2, from '/dev/video25':
 Duration: N/A, start: 672995.359539, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x9d7e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam25.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.9 q=8.4 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.369x 
video:146kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video25 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video25 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 10 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam25.jpg
10 /dev/video25: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam25.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video27 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam27.jpg
Input #0, video4linux2,v4l2, from '/dev/video27':
 Duration: N/A, start: 673000.069328, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x1f90e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam27.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=1.0 q=3.9 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.382x 
video:135kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video27 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video27 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 11 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam27.jpg
11 /dev/video27: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam27.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video29 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam29.jpg
Input #0, video4linux2,v4l2, from '/dev/video29':
 Duration: N/A, start: 673004.676618, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x22dde20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam29.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=1.0 q=9.3 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.385x 
video:165kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video29 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video29 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 12 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam29.jpg
12 /dev/video29: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam29.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video31 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam31.jpg
Input #0, video4linux2,v4l2, from '/dev/video31':
 Duration: N/A, start: 673009.555417, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x22f5e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam31.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.8 q=8.6 Lsize=N/A time=00:00:00.40 bitrate=N/A speed=0.335x 
video:141kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video31 image in: 4 seconds
linux_capture_photo_and_return_image_path( /dev/video31 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 13 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam31.jpg
13 /dev/video31: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam31.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video33 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam33.jpg
Input #0, video4linux2,v4l2, from '/dev/video33':
 Duration: N/A, start: 673014.171570, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x6d4e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam33.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.9 q=9.7 Lsize=N/A time=00:00:00.20 bitrate=N/A speed=0.172x 
video:156kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video33 image in: 3 seconds
linux_capture_photo_and_return_image_path( /dev/video33 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 14 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam33.jpg
14 /dev/video33: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam33.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video35 -frames:v 1 -f image2 /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam35.jpg
Input #0, video4linux2,v4l2, from '/dev/video35':
 Duration: N/A, start: 673018.565769, bitrate: 165888 kb/s
 Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
Stream mapping:
 Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x1667e20] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam35.jpg':
 Metadata:
 encoder : Lavf58.20.100
 Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x1080, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
 Metadata:
 encoder : Lavc58.35.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
frame= 1 fps=0.8 q=9.8 Lsize=N/A time=00:00:00.20 bitrate=N/A speed=0.167x 
video:148kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Captured /dev/video35 image in: 3 seconds
linux_capture_photo_and_return_image_path( /dev/video35 , /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/ , 15 ) RETURNS /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam35.jpg
15 /dev/video35: /var/www/html/sonascan/data/scans/10000000e1f45394/20210405184504/SonaCam35.jpg
/usr/bin/ffmpeg -y -hide_banner -ss 0:0:0 -r 15 -s 1920x1080 -f video4linux2 -i /dev/video37 -frames:v 1 -f image2




$ v4l2-ctl --all
Driver Info:
 Driver name : uvcvideo
 Card type : FHD Camera: FHD Camera
 Bus info : usb-0000:01:00.0-1.2.1.1
 Driver version : 5.10.17
 Capabilities : 0x84a00001
 Video Capture
 Metadata Capture
 Streaming
 Extended Pix Format
 Device Capabilities
 Device Caps : 0x04200001
 Video Capture
 Streaming
 Extended Pix Format
Media Driver Info:
 Driver name : uvcvideo
 Model : FHD Camera: FHD Camera
 Serial : 
 Bus info : usb-0000:01:00.0-1.2.1.1
 Media version : 5.10.17
 Hardware revision: 0x00000001 (1)
 Driver version : 5.10.17
Interface Info:
 ID : 0x03000002
 Type : V4L Video
Entity Info:
 ID : 0x00000001 (1)
 Name : FHD Camera: FHD Camera
 Function : V4L2 I/O
 Flags : default
 Pad 0x01000007 : 0: Sink
 Link 0x02000013: from remote pad 0x100000a of entity 'Extension 4': Data, Enabled, Immutable
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
 Width/Height : 1920/1080
 Pixel Format : 'YUYV' (YUYV 4:2:2)
 Field : None
 Bytes per Line : 3840
 Size Image : 4147200
 Colorspace : sRGB
 Transfer Function : Rec. 709
 YCbCr/HSV Encoding: ITU-R 601
 Quantization : Default (maps to Limited Range)
 Flags : 
Crop Capability Video Capture:
 Bounds : Left 0, Top 0, Width 1920, Height 1080
 Default : Left 0, Top 0, Width 1920, Height 1080
 Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 1920, Height 1080, Flags: 
Selection: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags: 
Streaming Parameters Video Capture:
 Capabilities : timeperframe
 Frames per second: 5.000 (5/1)
 Read buffers : 0
 brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128
 contrast 0x00980901 (int) : min=0 max=255 step=1 default=30 value=30
 saturation 0x00980902 (int) : min=0 max=100 step=1 default=64 value=64
 hue 0x00980903 (int) : min=-180 max=180 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool) : default=1 value=1
 gamma 0x00980910 (int) : min=90 max=150 step=1 default=120 value=120
 gain 0x00980913 (int) : min=4 max=8 step=1 default=5 value=5
 power_line_frequency 0x00980918 (menu) : min=0 max=2 default=1 value=1
 white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=1 default=4000 value=4000 flags=inactive
 sharpness 0x0098091b (int) : min=0 max=7 step=1 default=2 value=2
 backlight_compensation 0x0098091c (int) : min=0 max=2 step=1 default=2 value=2
 exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=3
 exposure_absolute 0x009a0902 (int) : min=9 max=2500 step=1 default=123 value=123 flags=inactive
error 22 getting ext_ctrl Exposure, Auto Priority



-
FFMPEG Output File is Empty Nothing was Encoded (for a Picture) ?
4 mars 2023, par Sarah SzaboI have a strange issue effecting one of my programs that does bulk media conversions using ffmpeg from the command line, however this effects me using it directly from the shell as well :


ffmpeg -i INPUT.mkv -ss 0:30 -y -qscale:v 2 -frames:v 1 -f image2 -huffman optimal "OUTPUT.png"

fails every run with the error message :
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)


This only happens with very specific videos, and seemingly no other videos. File type is usually .webm. These files have been downloaded properly (usually from yt-dlp), and I have tried re-downloading them just to verify their integrity.


One such file from a colleague was : https://www.dropbox.com/s/xkucr2z5ra1p2oh/Triggerheart%20Execlica%20OST%20%28Arrange%29%20-%20Crueltear%20Ending.mkv?dl=0


Is there a subtle issue with the command string ?


Notes :


removing
-huffman optimal
had no effect

moving
-ss
to before-i
had no effect

removing
-f image2 had no effect


Full Log :


sarah@MidnightStarSign:~/Music/Playlists/Indexing/Indexing Temp$ ffmpeg -i Triggerheart\ Execlica\ OST\ \(Arrange\)\ -\ Crueltear\ Ending.mkv -ss 0:30 -y -qscale:v 2 -frames:v 1 -f image2 -huffman optimal "TEST.png"
ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
 built with gcc 12.2.0 (GCC)
 configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-version3 --enable-vulkan
 libavutil 57. 28.100 / 57. 28.100
 libavcodec 59. 37.100 / 59. 37.100
 libavformat 59. 27.100 / 59. 27.100
 libavdevice 59. 7.100 / 59. 7.100
 libavfilter 8. 44.100 / 8. 44.100
 libswscale 6. 7.100 / 6. 7.100
 libswresample 4. 7.100 / 4. 7.100
 libpostproc 56. 6.100 / 56. 6.100
[matroska,webm @ 0x55927f484740] Could not find codec parameters for stream 2 (Attachment: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, matroska,webm, from 'Triggerheart Execlica OST (Arrange) - Crueltear Ending.mkv':
 Metadata:
 title : TriggerHeart Exelica PS2 & 360 Arrange ー 16 - Crueltear Ending
 PURL : https://www.youtube.com/watch?v=zJ0bEa_8xEg
 COMMENT : https://www.youtube.com/watch?v=zJ0bEa_8xEg
 ARTIST : VinnyVynce
 DATE : 20170905
 ENCODER : Lavf59.27.100
 Duration: 00:00:30.00, start: -0.007000, bitrate: 430 kb/s
 Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709), 720x720, SAR 1:1 DAR 1:1, 25 fps, 25 tbr, 1k tbn (default)
 Metadata:
 DURATION : 00:00:29.934000000
 Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
 Metadata:
 DURATION : 00:00:30.001000000
 Stream #0:2: Attachment: none
 Metadata:
 filename : cover.webp
 mimetype : image/webp
Codec AVOption huffman (Huffman table strategy) specified for output file #0 (TEST.png) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
 Stream #0:0 -> #0:0 (vp9 (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'TEST.png':
 Metadata:
 title : TriggerHeart Exelica PS2 & 360 Arrange ー 16 - Crueltear Ending
 PURL : https://www.youtube.com/watch?v=zJ0bEa_8xEg
 COMMENT : https://www.youtube.com/watch?v=zJ0bEa_8xEg
 ARTIST : VinnyVynce
 DATE : 20170905
 encoder : Lavf59.27.100
 Stream #0:0(eng): Video: png, rgb24, 720x720 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
 Metadata:
 DURATION : 00:00:29.934000000
 encoder : Lavc59.37.100 png
frame= 0 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed= 0x 
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)



Manjaro OS System Specs :


System:
 Kernel: 6.1.12-1-MANJARO arch: x86_64 bits: 64 compiler: gcc v: 12.2.1
 parameters: BOOT_IMAGE=/@/boot/vmlinuz-6.1-x86_64
 root=UUID=f11386cf-342d-47ac-84e6-484b7b2f377d rw rootflags=subvol=@
 radeon.modeset=1 nvdia-drm.modeset=1 quiet
 cryptdevice=UUID=059df4b4-5be4-44d6-a23a-de81135eb5b4:luks-disk
 root=/dev/mapper/luks-disk apparmor=1 security=apparmor
 resume=/dev/mapper/luks-swap udev.log_priority=3
 Desktop: KDE Plasma v: 5.26.5 tk: Qt v: 5.15.8 wm: kwin_x11 vt: 1 dm: SDDM
 Distro: Manjaro Linux base: Arch Linux
Machine:
 Type: Desktop Mobo: ASUSTeK model: PRIME X570-PRO v: Rev X.0x
 serial: <superuser required="required"> UEFI: American Megatrends v: 4408
 date: 10/27/2022
Battery:
 Message: No system battery data found. Is one present?
Memory:
 RAM: total: 62.71 GiB used: 27.76 GiB (44.3%)
 RAM Report: permissions: Unable to run dmidecode. Root privileges required.
CPU:
 Info: model: AMD Ryzen 9 5950X bits: 64 type: MT MCP arch: Zen 3+ gen: 4
 level: v3 note: check built: 2022 process: TSMC n6 (7nm) family: 0x19 (25)
 model-id: 0x21 (33) stepping: 0 microcode: 0xA201016
 Topology: cpus: 1x cores: 16 tpc: 2 threads: 32 smt: enabled cache:
 L1: 1024 KiB desc: d-16x32 KiB; i-16x32 KiB L2: 8 MiB desc: 16x512 KiB
 L3: 64 MiB desc: 2x32 MiB
 Speed (MHz): avg: 4099 high: 4111 min/max: 2200/6358 boost: disabled
 scaling: driver: acpi-cpufreq governor: schedutil cores: 1: 4099 2: 4095
 3: 4102 4: 4100 5: 4097 6: 4100 7: 4110 8: 4111 9: 4083 10: 4099 11: 4100
 12: 4094 13: 4097 14: 4101 15: 4100 16: 4099 17: 4100 18: 4097 19: 4098
 20: 4095 21: 4100 22: 4099 23: 4099 24: 4105 25: 4098 26: 4100 27: 4100
 28: 4092 29: 4103 30: 4101 31: 4100 32: 4099 bogomips: 262520
 Flags: 3dnowprefetch abm adx aes aperfmperf apic arat avic avx avx2 bmi1
 bmi2 bpext cat_l3 cdp_l3 clflush clflushopt clwb clzero cmov cmp_legacy
 constant_tsc cpb cpuid cqm cqm_llc cqm_mbm_local cqm_mbm_total
 cqm_occup_llc cr8_legacy cx16 cx8 de decodeassists erms extapic
 extd_apicid f16c flushbyasid fma fpu fsgsbase fsrm fxsr fxsr_opt ht
 hw_pstate ibpb ibrs ibs invpcid irperf lahf_lm lbrv lm mba mca mce
 misalignsse mmx mmxext monitor movbe msr mtrr mwaitx nonstop_tsc nopl npt
 nrip_save nx ospke osvw overflow_recov pae pat pausefilter pclmulqdq
 pdpe1gb perfctr_core perfctr_llc perfctr_nb pfthreshold pge pku pni popcnt
 pse pse36 rapl rdpid rdpru rdrand rdseed rdt_a rdtscp rep_good sep sha_ni
 skinit smap smca smep ssbd sse sse2 sse4_1 sse4_2 sse4a ssse3 stibp succor
 svm svm_lock syscall tce topoext tsc tsc_scale umip v_spec_ctrl
 v_vmsave_vmload vaes vgif vmcb_clean vme vmmcall vpclmulqdq wbnoinvd wdt
 x2apic xgetbv1 xsave xsavec xsaveerptr xsaveopt xsaves
 Vulnerabilities:
 Type: itlb_multihit status: Not affected
 Type: l1tf status: Not affected
 Type: mds status: Not affected
 Type: meltdown status: Not affected
 Type: mmio_stale_data status: Not affected
 Type: retbleed status: Not affected
 Type: spec_store_bypass mitigation: Speculative Store Bypass disabled via
 prctl
 Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer
 sanitization
 Type: spectre_v2 mitigation: Retpolines, IBPB: conditional, IBRS_FW,
 STIBP: always-on, RSB filling, PBRSB-eIBRS: Not affected
 Type: srbds status: Not affected
 Type: tsx_async_abort status: Not affected
Graphics:
 Device-1: NVIDIA GA104 [GeForce RTX 3070] vendor: ASUSTeK driver: nvidia
 v: 525.89.02 alternate: nouveau,nvidia_drm non-free: 525.xx+
 status: current (as of 2023-02) arch: Ampere code: GAxxx
 process: TSMC n7 (7nm) built: 2020-22 pcie: gen: 4 speed: 16 GT/s lanes: 8
 link-max: lanes: 16 bus-ID: 0b:00.0 chip-ID: 10de:2484 class-ID: 0300
 Device-2: AMD Cape Verde PRO [Radeon HD 7750/8740 / R7 250E]
 vendor: VISIONTEK driver: radeon v: kernel alternate: amdgpu arch: GCN-1
 code: Southern Islands process: TSMC 28nm built: 2011-20 pcie: gen: 3
 speed: 8 GT/s lanes: 8 link-max: lanes: 16 ports: active: DP-3,DP-4
 empty: DP-1, DP-2, DP-5, DP-6 bus-ID: 0c:00.0 chip-ID: 1002:683f
 class-ID: 0300 temp: 54.0 C
 Device-3: Microdia USB 2.0 Camera type: USB driver: snd-usb-audio,uvcvideo
 bus-ID: 9-2:3 chip-ID: 0c45:6367 class-ID: 0102 serial: <filter>
 Display: x11 server: X.Org v: 21.1.7 with: Xwayland v: 22.1.8
 compositor: kwin_x11 driver: X: loaded: modesetting,nvidia dri: radeonsi
 gpu: radeon display-ID: :0 screens: 1
 Screen-1: 0 s-res: 5760x2160 s-dpi: 80 s-size: 1829x686mm (72.01x27.01")
 s-diag: 1953mm (76.91")
 Monitor-1: DP-1 pos: 1-2 res: 1920x1080 dpi: 93
 size: 527x296mm (20.75x11.65") diag: 604mm (23.8") modes: N/A
 Monitor-2: DP-1-3 pos: 2-1 res: 1920x1080 dpi: 82
 size: 598x336mm (23.54x13.23") diag: 686mm (27.01") modes: N/A
 Monitor-3: DP-1-4 pos: 1-1 res: 1920x1080 dpi: 93
 size: 527x296mm (20.75x11.65") diag: 604mm (23.8") modes: N/A
 Monitor-4: DP-3 pos: primary,2-2 res: 1920x1080 dpi: 82
 size: 598x336mm (23.54x13.23") diag: 686mm (27.01") modes: N/A
 Monitor-5: DP-4 pos: 2-4 res: 1920x1080 dpi: 82
 size: 598x336mm (23.54x13.23") diag: 686mm (27.01") modes: N/A
 Monitor-6: HDMI-0 pos: 1-3 res: 1920x1080 dpi: 93
 size: 527x296mm (20.75x11.65") diag: 604mm (23.8") modes: N/A
 API: OpenGL v: 4.6.0 NVIDIA 525.89.02 renderer: NVIDIA GeForce RTX
 3070/PCIe/SSE2 direct-render: Yes
Audio:
 Device-1: NVIDIA GA104 High Definition Audio vendor: ASUSTeK
 driver: snd_hda_intel bus-ID: 5-1:2 v: kernel chip-ID: 30be:1019 pcie:
 class-ID: 0102 gen: 4 speed: 16 GT/s lanes: 8 link-max: lanes: 16
 bus-ID: 0b:00.1 chip-ID: 10de:228b class-ID: 0403
 Device-2: AMD Oland/Hainan/Cape Verde/Pitcairn HDMI Audio [Radeon HD 7000
 Series] vendor: VISIONTEK driver: snd_hda_intel v: kernel pcie: gen: 3
 speed: 8 GT/s lanes: 8 link-max: lanes: 16 bus-ID: 0c:00.1
 chip-ID: 1002:aab0 class-ID: 0403
 Device-3: AMD Starship/Matisse HD Audio vendor: ASUSTeK
 driver: snd_hda_intel v: kernel pcie: gen: 4 speed: 16 GT/s lanes: 16
 bus-ID: 0e:00.4 chip-ID: 1022:1487 class-ID: 0403
 Device-4: Schiit Audio Unison Universal Dac type: USB driver: snd-usb-audio
 Device-5: JMTek LLC. Plugable USB Audio Device type: USB
 driver: hid-generic,snd-usb-audio,usbhid bus-ID: 5-2:3 chip-ID: 0c76:120b
 class-ID: 0300 serial: <filter>
 Device-6: ASUSTek ASUS AI Noise-Cancelling Mic Adapter type: USB
 driver: hid-generic,snd-usb-audio,usbhid bus-ID: 5-4:4 chip-ID: 0b05:194e
 class-ID: 0300 serial: <filter>
 Device-7: Microdia USB 2.0 Camera type: USB driver: snd-usb-audio,uvcvideo
 bus-ID: 9-2:3 chip-ID: 0c45:6367 class-ID: 0102 serial: <filter>
 Sound API: ALSA v: k6.1.12-1-MANJARO running: yes
 Sound Interface: sndio v: N/A running: no
 Sound Server-1: PulseAudio v: 16.1 running: no
 Sound Server-2: PipeWire v: 0.3.65 running: yes
Network:
 Device-1: Intel I211 Gigabit Network vendor: ASUSTeK driver: igb v: kernel
 pcie: gen: 1 speed: 2.5 GT/s lanes: 1 port: f000 bus-ID: 07:00.0
 chip-ID: 8086:1539 class-ID: 0200
 IF: enp7s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
 IP v4: <filter> type: dynamic noprefixroute scope: global
 broadcast: <filter>
 IP v6: <filter> type: noprefixroute scope: link
 IF-ID-1: docker0 state: down mac: <filter>
 IP v4: <filter> scope: global broadcast: <filter>
 WAN IP: <filter>
Bluetooth:
 Device-1: Cambridge Silicon Radio Bluetooth Dongle (HCI mode) type: USB
 driver: btusb v: 0.8 bus-ID: 5-5.3:7 chip-ID: 0a12:0001 class-ID: e001
 Report: rfkill ID: hci0 rfk-id: 0 state: up address: see --recommends
Logical:
 Message: No logical block device data found.
 Device-1: luks-c847cf9f-c6b5-4624-a25e-4531e318851a maj-min: 254:2
 type: LUKS dm: dm-2 size: 3.64 TiB
 Components:
 p-1: sda1 maj-min: 8:1 size: 3.64 TiB
 Device-2: luks-swap maj-min: 254:1 type: LUKS dm: dm-1 size: 12 GiB
 Components:
 p-1: nvme0n1p2 maj-min: 259:2 size: 12 GiB
 Device-3: luks-disk maj-min: 254:0 type: LUKS dm: dm-0 size: 919.01 GiB
 Components:
 p-1: nvme0n1p3 maj-min: 259:3 size: 919.01 GiB
RAID:
 Message: No RAID data found.
Drives:
 Local Storage: total: 9.1 TiB used: 2.79 TiB (30.6%)
 SMART Message: Unable to run smartctl. Root privileges required.
 ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Western Digital
 model: WDS100T3X0C-00SJG0 size: 931.51 GiB block-size: physical: 512 B
 logical: 512 B speed: 31.6 Gb/s lanes: 4 type: SSD serial: <filter>
 rev: 111110WD temp: 53.9 C scheme: GPT
 ID-2: /dev/nvme1n1 maj-min: 259:4 vendor: Western Digital
 model: WDS100T2B0C-00PXH0 size: 931.51 GiB block-size: physical: 512 B
 logical: 512 B speed: 31.6 Gb/s lanes: 4 type: SSD serial: <filter>
 rev: 211070WD temp: 46.9 C scheme: GPT
 ID-3: /dev/sda maj-min: 8:0 vendor: Western Digital
 model: WD4005FZBX-00K5WB0 size: 3.64 TiB block-size: physical: 4096 B
 logical: 512 B speed: 6.0 Gb/s type: HDD rpm: 7200 serial: <filter>
 rev: 1A01 scheme: GPT
 ID-4: /dev/sdb maj-min: 8:16 vendor: Western Digital
 model: WD4005FZBX-00K5WB0 size: 3.64 TiB block-size: physical: 4096 B
 logical: 512 B speed: 6.0 Gb/s type: HDD rpm: 7200 serial: <filter>
 rev: 1A01 scheme: GPT
 ID-5: /dev/sdc maj-min: 8:32 type: USB vendor: SanDisk
 model: Gaming Xbox 360 size: 7.48 GiB block-size: physical: 512 B
 logical: 512 B type: N/A serial: <filter> rev: 8.02 scheme: MBR
 SMART Message: Unknown USB bridge. Flash drive/Unsupported enclosure?
 Message: No optical or floppy data found.
Partition:
 ID-1: / raw-size: 919.01 GiB size: 919.01 GiB (100.00%)
 used: 611.14 GiB (66.5%) fs: btrfs dev: /dev/dm-0 maj-min: 254:0
 mapped: luks-disk label: N/A uuid: N/A
 ID-2: /boot/efi raw-size: 512 MiB size: 511 MiB (99.80%)
 used: 40.2 MiB (7.9%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:1 label: EFI
 uuid: 8922-E04D
 ID-3: /home raw-size: 919.01 GiB size: 919.01 GiB (100.00%)
 used: 611.14 GiB (66.5%) fs: btrfs dev: /dev/dm-0 maj-min: 254:0
 mapped: luks-disk label: N/A uuid: N/A
 ID-4: /run/media/sarah/ConvergentRefuge raw-size: 3.64 TiB
 size: 3.64 TiB (100.00%) used: 2.19 TiB (60.1%) fs: btrfs dev: /dev/dm-2
 maj-min: 254:2 mapped: luks-c847cf9f-c6b5-4624-a25e-4531e318851a
 label: ConvergentRefuge uuid: 7d295e73-4143-4eb1-9d22-75a06b1d2984
 ID-5: /run/media/sarah/MSS_EXtended raw-size: 475.51 GiB
 size: 475.51 GiB (100.00%) used: 1.48 GiB (0.3%) fs: btrfs
 dev: /dev/nvme1n1p1 maj-min: 259:5 label: MSS EXtended
 uuid: f98b3a12-e0e4-48c7-91c2-6e3aa6dcd32c
Swap:
 Kernel: swappiness: 60 (default) cache-pressure: 100 (default)
 ID-1: swap-1 type: partition size: 12 GiB used: 6.86 GiB (57.2%)
 priority: -2 dev: /dev/dm-1 maj-min: 254:1 mapped: luks-swap label: SWAP
 uuid: c8991364-85a7-4e6c-8380-49cd5bd7a873
Unmounted:
 ID-1: /dev/nvme1n1p2 maj-min: 259:6 size: 456 GiB fs: ntfs label: N/A
 uuid: 5ECA358FCA356485
 ID-2: /dev/sdb1 maj-min: 8:17 size: 3.64 TiB fs: ntfs
 label: JerichoVariance uuid: 1AB22D5664889CBD
 ID-3: /dev/sdc1 maj-min: 8:33 size: 3.57 GiB fs: iso9660
 ID-4: /dev/sdc2 maj-min: 8:34 size: 4 MiB fs: vfat label: MISO_EFI
 uuid: 5C67-4BF8
USB:
 Hub-1: 1-0:1 info: Hi-speed hub with single TT ports: 4 rev: 2.0
 speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900
 Hub-2: 1-2:2 info: Hitachi ports: 4 rev: 2.1 speed: 480 Mb/s
 chip-ID: 045b:0209 class-ID: 0900
 Device-1: 1-2.4:3 info: Microsoft Xbox One Controller (Firmware 2015)
 type: <vendor specific="specific"> driver: xpad interfaces: 3 rev: 2.0 speed: 12 Mb/s
 power: 500mA chip-ID: 045e:02dd class-ID: ff00 serial: <filter>
 Hub-3: 2-0:1 info: Super-speed hub ports: 4 rev: 3.0 speed: 5 Gb/s
 chip-ID: 1d6b:0003 class-ID: 0900
 Hub-4: 2-2:2 info: Hitachi ports: 4 rev: 3.0 speed: 5 Gb/s
 chip-ID: 045b:0210 class-ID: 0900
 Hub-5: 3-0:1 info: Hi-speed hub with single TT ports: 1 rev: 2.0
 speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900
 Hub-6: 3-1:2 info: VIA Labs Hub ports: 4 rev: 2.1 speed: 480 Mb/s
 power: 100mA chip-ID: 2109:3431 class-ID: 0900
 Hub-7: 3-1.2:3 info: VIA Labs VL813 Hub ports: 4 rev: 2.1 speed: 480 Mb/s
 chip-ID: 2109:2813 class-ID: 0900
 Hub-8: 4-0:1 info: Super-speed hub ports: 4 rev: 3.0 speed: 5 Gb/s
 chip-ID: 1d6b:0003 class-ID: 0900
 Hub-9: 4-2:2 info: VIA Labs VL813 Hub ports: 4 rev: 3.0 speed: 5 Gb/s
 chip-ID: 2109:0813 class-ID: 0900
 Hub-10: 5-0:1 info: Hi-speed hub with single TT ports: 6 rev: 2.0
 speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900
 Device-1: 5-1:2 info: Schiit Audio Unison Universal Dac type: Audio
 driver: snd-usb-audio interfaces: 2 rev: 2.0 speed: 480 Mb/s power: 500mA
 chip-ID: 30be:1019 class-ID: 0102
 Device-2: 5-2:3 info: JMTek LLC. Plugable USB Audio Device type: Audio,HID
 driver: hid-generic,snd-usb-audio,usbhid interfaces: 4 rev: 1.1
 speed: 12 Mb/s power: 100mA chip-ID: 0c76:120b class-ID: 0300
 serial: <filter>
 Device-3: 5-4:4 info: ASUSTek ASUS AI Noise-Cancelling Mic Adapter
 type: Audio,HID driver: hid-generic,snd-usb-audio,usbhid interfaces: 4
 rev: 1.1 speed: 12 Mb/s power: 100mA chip-ID: 0b05:194e class-ID: 0300
 serial: <filter>
 Hub-11: 5-5:5 info: Genesys Logic Hub ports: 4 rev: 2.0 speed: 480 Mb/s
 power: 100mA chip-ID: 05e3:0608 class-ID: 0900
 Device-1: 5-5.3:7 info: Cambridge Silicon Radio Bluetooth Dongle (HCI mode)
 type: Bluetooth driver: btusb interfaces: 2 rev: 2.0 speed: 12 Mb/s
 power: 100mA chip-ID: 0a12:0001 class-ID: e001
 Hub-12: 5-6:6 info: Genesys Logic Hub ports: 4 rev: 2.0 speed: 480 Mb/s
 power: 100mA chip-ID: 05e3:0608 class-ID: 0900
 Hub-13: 6-0:1 info: Super-speed hub ports: 4 rev: 3.1 speed: 10 Gb/s
 chip-ID: 1d6b:0003 class-ID: 0900
 Hub-14: 7-0:1 info: Hi-speed hub with single TT ports: 6 rev: 2.0
 speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900
 Device-1: 7-2:2 info: SanDisk Cruzer Micro Flash Drive type: Mass Storage
 driver: usb-storage interfaces: 1 rev: 2.0 speed: 480 Mb/s power: 200mA
 chip-ID: 0781:5151 class-ID: 0806 serial: <filter>
 Device-2: 7-4:3 info: ASUSTek AURA LED Controller type: HID
 driver: hid-generic,usbhid interfaces: 2 rev: 2.0 speed: 12 Mb/s power: 16mA
 chip-ID: 0b05:18f3 class-ID: 0300 serial: <filter>
 Hub-15: 8-0:1 info: Super-speed hub ports: 4 rev: 3.1 speed: 10 Gb/s
 chip-ID: 1d6b:0003 class-ID: 0900
 Hub-16: 9-0:1 info: Hi-speed hub with single TT ports: 4 rev: 2.0
 speed: 480 Mb/s chip-ID: 1d6b:0002 class-ID: 0900
 Hub-17: 9-1:2 info: Terminus FE 2.1 7-port Hub ports: 7 rev: 2.0
 speed: 480 Mb/s power: 100mA chip-ID: 1a40:0201 class-ID: 0900
 Device-1: 9-1.1:4 info: Sunplus Innovation Gaming mouse [Philips SPK9304]
 type: Mouse driver: hid-generic,usbhid interfaces: 1 rev: 2.0 speed: 1.5 Mb/s
 power: 98mA chip-ID: 1bcf:08a0 class-ID: 0301
 Device-2: 9-1.5:6 info: Microdia Backlit Gaming Keyboard
 type: Keyboard,Mouse driver: hid-generic,usbhid interfaces: 2 rev: 2.0
 speed: 12 Mb/s power: 400mA chip-ID: 0c45:652f class-ID: 0301
 Device-3: 9-1.6:7 info: HUION H420 type: Mouse,HID driver: uclogic,usbhid
 interfaces: 3 rev: 1.1 speed: 12 Mb/s power: 100mA chip-ID: 256c:006e
 class-ID: 0300
 Hub-18: 9-1.7:8 info: Terminus Hub ports: 4 rev: 2.0 speed: 480 Mb/s
 power: 100mA chip-ID: 1a40:0101 class-ID: 0900
 Device-1: 9-2:3 info: Microdia USB 2.0 Camera type: Video,Audio
 driver: snd-usb-audio,uvcvideo interfaces: 4 rev: 2.0 speed: 480 Mb/s
 power: 500mA chip-ID: 0c45:6367 class-ID: 0102 serial: <filter>
 Device-2: 9-4:11 info: VKB-Sim © Alex Oz 2021 VKBsim Gladiator EVO L
 type: HID driver: hid-generic,usbhid interfaces: 1 rev: 2.0 speed: 12 Mb/s
 power: 500mA chip-ID: 231d:0201 class-ID: 0300
 Hub-19: 10-0:1 info: Super-speed hub ports: 4 rev: 3.1 speed: 10 Gb/s
 chip-ID: 1d6b:0003 class-ID: 0900
Sensors:
 System Temperatures: cpu: 38.0 C mobo: 41.0 C
 Fan Speeds (RPM): fan-1: 702 fan-2: 747 fan-3: 938 fan-4: 889 fan-5: 3132
 fan-6: 0 fan-7: 0
 GPU: device: nvidia screen: :0.0 temp: 49 C fan: 0% device: radeon
 temp: 53.0 C
Info:
 Processes: 842 Uptime: 3h 11m wakeups: 0 Init: systemd v: 252
 default: graphical tool: systemctl Compilers: gcc: 12.2.1 alt: 10/11
 clang: 15.0.7 Packages: 2158 pm: pacman pkgs: 2110 libs: 495 tools: pamac,yay
 pm: flatpak pkgs: 31 pm: snap pkgs: 17 Shell: Bash v: 5.1.16
 running-in: yakuake inxi: 3.3.25
</filter></filter></filter></filter></filter></filter></vendor></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></filter></superuser>


-
using ffmpeg libraray to write to a mp4, ffprobe shows there are 100 frames and 100 packets, but av_interleaved_write_frame only called 50 times
2 mai 2023, par ollydbg23here is my code to generate a mp4 file by using ffmpeg and opencv library. The opencv library is only try to generate 100 images(frames), and ffmpeg library is to compress the images to a mp4 files.


Here is the working code :


#include <iostream>
#include <vector>
#include <cstring>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <opencv2></opencv2>opencv.hpp>
extern "C" {
#include <libavutil></libavutil>imgutils.h>
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>opt.h>
}

#include<cstdlib> // to generate time stamps

using namespace std;
using namespace cv;

int main()
{
 // Set up input frames as BGR byte arrays
 vector<mat> frames;

 int width = 640;
 int height = 480;
 int num_frames = 100;
 Scalar black(0, 0, 0);
 Scalar white(255, 255, 255);
 int font = FONT_HERSHEY_SIMPLEX;
 double font_scale = 1.0;
 int thickness = 2;

 for (int i = 0; i < num_frames; i++) {
 Mat frame = Mat::zeros(height, width, CV_8UC3);
 putText(frame, std::to_string(i), Point(width / 2 - 50, height / 2), font, font_scale, white, thickness);
 frames.push_back(frame);
 }

 // generate a serial of time stamps which is used to set the PTS value
 // suppose they are in ms unit, the time interval is between 30ms to 59ms
 vector<int> timestamps;

 for (int i = 0; i < num_frames; i++) {
 int timestamp;
 if (i == 0)
 timestamp = 0;
 else
 {
 int random = 30 + (rand() % 30);
 timestamp = timestamps[i-0] + random;
 }

 timestamps.push_back(timestamp);
 }

 // Populate frames with BGR byte arrays

 // Initialize FFmpeg
 //av_register_all();

 // Set up output file
 AVFormatContext* outFormatCtx = nullptr;
 //AVCodec* outCodec = nullptr;
 AVCodecContext* outCodecCtx = nullptr;
 //AVStream* outStream = nullptr;
 //AVPacket outPacket;

 const char* outFile = "output.mp4";
 int outWidth = frames[0].cols;
 int outHeight = frames[0].rows;
 int fps = 25;

 // Open the output file context
 avformat_alloc_output_context2(&outFormatCtx, nullptr, nullptr, outFile);
 if (!outFormatCtx) {
 cerr << "Error: Could not allocate output format context" << endl;
 return -1;
 }

 // Open the output file
 if (avio_open(&outFormatCtx->pb, outFile, AVIO_FLAG_WRITE) < 0) {
 cerr << "Error opening output file" << std::endl;
 return -1;
 }

 // Set up output codec
 const AVCodec* outCodec = avcodec_find_encoder(AV_CODEC_ID_H264);
 if (!outCodec) {
 cerr << "Error: Could not find H.264 codec" << endl;
 return -1;
 }

 outCodecCtx = avcodec_alloc_context3(outCodec);
 if (!outCodecCtx) {
 cerr << "Error: Could not allocate output codec context" << endl;
 return -1;
 }
 outCodecCtx->codec_id = AV_CODEC_ID_H264;
 outCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
 outCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
 outCodecCtx->width = outWidth;
 outCodecCtx->height = outHeight;
 //outCodecCtx->time_base = { 1, fps*1000 }; // 25000
 outCodecCtx->time_base = { 1, fps}; // 25000
 outCodecCtx->framerate = {fps, 1}; // 25
 outCodecCtx->bit_rate = 4000000;

 //https://github.com/leandromoreira/ffmpeg-libav-tutorial
 //We set the flag AV_CODEC_FLAG_GLOBAL_HEADER which tells the encoder that it can use the global headers.
 if (outFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
 {
 outCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; //
 }

 // Open output codec
 if (avcodec_open2(outCodecCtx, outCodec, nullptr) < 0) {
 cerr << "Error: Could not open output codec" << endl;
 return -1;
 }

 // Create output stream
 AVStream* outStream = avformat_new_stream(outFormatCtx, outCodec);
 if (!outStream) {
 cerr << "Error: Could not allocate output stream" << endl;
 return -1;
 }

 // Configure output stream parameters (e.g., time base, codec parameters, etc.)
 // ...

 // Connect output stream to format context
 outStream->codecpar->codec_id = outCodecCtx->codec_id;
 outStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 outStream->codecpar->width = outCodecCtx->width;
 outStream->codecpar->height = outCodecCtx->height;
 outStream->codecpar->format = outCodecCtx->pix_fmt;
 outStream->time_base = outCodecCtx->time_base;

 int ret = avcodec_parameters_from_context(outStream->codecpar, outCodecCtx);
 if (ret < 0) {
 cerr << "Error: Could not copy codec parameters to output stream" << endl;
 return -1;
 }

 outStream->avg_frame_rate = outCodecCtx->framerate;
 //outStream->id = outFormatCtx->nb_streams++; <--- We shouldn't modify outStream->id

 ret = avformat_write_header(outFormatCtx, nullptr);
 if (ret < 0) {
 cerr << "Error: Could not write output header" << endl;
 return -1;
 }

 // Convert frames to YUV format and write to output file
 int frame_count = -1;
 for (const auto& frame : frames) {
 frame_count++;
 AVFrame* yuvFrame = av_frame_alloc();
 if (!yuvFrame) {
 cerr << "Error: Could not allocate YUV frame" << endl;
 return -1;
 }
 av_image_alloc(yuvFrame->data, yuvFrame->linesize, outWidth, outHeight, AV_PIX_FMT_YUV420P, 32);

 yuvFrame->width = outWidth;
 yuvFrame->height = outHeight;
 yuvFrame->format = AV_PIX_FMT_YUV420P;

 // Convert BGR frame to YUV format
 Mat yuvMat;
 cvtColor(frame, yuvMat, COLOR_BGR2YUV_I420);
 memcpy(yuvFrame->data[0], yuvMat.data, outWidth * outHeight);
 memcpy(yuvFrame->data[1], yuvMat.data + outWidth * outHeight, outWidth * outHeight / 4);
 memcpy(yuvFrame->data[2], yuvMat.data + outWidth * outHeight * 5 / 4, outWidth * outHeight / 4);

 // Set up output packet
 //av_init_packet(&outPacket); //error C4996: 'av_init_packet': was declared deprecated
 AVPacket* outPacket = av_packet_alloc();
 memset(outPacket, 0, sizeof(outPacket)); //Use memset instead of av_init_packet (probably unnecessary).
 //outPacket->data = nullptr;
 //outPacket->size = 0;

 // set the frame pts, do I have to set the package pts?

 // yuvFrame->pts = av_rescale_q(timestamps[frame_count]*25, outCodecCtx->time_base, outStream->time_base); //Set PTS timestamp
 yuvFrame->pts = av_rescale_q(frame_count*frame_count, outCodecCtx->time_base, outStream->time_base); //Set PTS timestamp

 // Encode frame and write to output file
 int ret = avcodec_send_frame(outCodecCtx, yuvFrame);
 if (ret < 0) {
 cerr << "Error: Could not send frame to output codec" << endl;
 return -1;
 }
 while (ret >= 0)
 {
 ret = avcodec_receive_packet(outCodecCtx, outPacket);

 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 {
 int abc;
 abc++;
 break;
 }
 else if (ret < 0)
 {
 cerr << "Error: Could not receive packet from output codec" << endl;
 return -1;
 }

 //av_packet_rescale_ts(&outPacket, outCodecCtx->time_base, outStream->time_base);

 outPacket->stream_index = outStream->index;

 outPacket->duration = av_rescale_q(1, outCodecCtx->time_base, outStream->time_base); // Set packet duration

 ret = av_interleaved_write_frame(outFormatCtx, outPacket);

 static int call_write = 0;

 call_write++;
 printf("av_interleaved_write_frame %d\n", call_write);

 av_packet_unref(outPacket);
 if (ret < 0) {
 cerr << "Error: Could not write packet to output file" << endl;
 return -1;
 }
 }

 av_frame_free(&yuvFrame);
 }

 // Flush the encoder
 ret = avcodec_send_frame(outCodecCtx, nullptr);
 if (ret < 0) {
 std::cerr << "Error flushing encoder: " << std::endl;
 return -1;
 }

 while (ret >= 0) {
 AVPacket* pkt = av_packet_alloc();
 if (!pkt) {
 std::cerr << "Error allocating packet" << std::endl;
 return -1;
 }
 ret = avcodec_receive_packet(outCodecCtx, pkt);

 // Write the packet to the output file
 if (ret == 0)
 {
 pkt->stream_index = outStream->index;
 pkt->duration = av_rescale_q(1, outCodecCtx->time_base, outStream->time_base); // <---- Set packet duration
 ret = av_interleaved_write_frame(outFormatCtx, pkt);
 av_packet_unref(pkt);
 if (ret < 0) {
 std::cerr << "Error writing packet to output file: " << std::endl;
 return -1;
 }
 }
 }


 // Write output trailer
 av_write_trailer(outFormatCtx);

 // Clean up
 avcodec_close(outCodecCtx);
 avcodec_free_context(&outCodecCtx);
 avformat_free_context(outFormatCtx);

 return 0;
}

</int></mat></cstdlib></stdexcept></sstream></fstream></cstring></vector></iostream>


Note that I have used the
ffprobe
tool(one of the tool from ffmpeg) to inspect the generated mp4 files.

I see that the mp4 file has 100 frames and 100 packets, but in my code, I have such lines :


static int call_write = 0;

 call_write++;
 printf("av_interleaved_write_frame %d\n", call_write);



I just see that the
av_interleaved_write_frame
function is only called 50 times, not the expected 100 times, anyone can explain it ?

Thanks.


BTW, from the ffmpeg document( see here : For video, it should typically contain one compressed frame ), I see that a
packet
mainly has one videoframe
, so theffprobe
's result looks correct.

Here is the command I used to inspect the mp4 file :


ffprobe -show_frames output.mp4 >> frames.txt
ffprobe -show_packets output.mp4 >> packets.txt



My testing code is derived from an answer in another question here : avformat_write_header() function call crashed when I try to save several RGB data to a output.mp4 file