
Recherche avancée
Médias (1)
-
La conservation du net art au musée. Les stratégies à l’œuvre
26 mai 2011
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (81)
-
Emballe médias : à quoi cela sert ?
4 février 2011, parCe plugin vise à gérer des sites de mise en ligne de documents de tous types.
Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ; -
Gestion des droits de création et d’édition des objets
8 février 2011, parPar défaut, beaucoup de fonctionnalités sont limitées aux administrateurs mais restent configurables indépendamment pour modifier leur statut minimal d’utilisation notamment : la rédaction de contenus sur le site modifiables dans la gestion des templates de formulaires ; l’ajout de notes aux articles ; l’ajout de légendes et d’annotations sur les images ;
-
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 (...)
Sur d’autres sites (3542)
-
FFMPEG Without Headers is Causing Video To Be Height 0X0
21 novembre 2022, par Devin DixonI am grabbing a stream from X11 and streaming it to other sources like Node Media Server and Twitch. Except, I get audio only with no video and the resolution size says 0X0.


My ffmpeg is command is this :


/usr/bin/ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -video_size 1920x1080 -y -v info -f x11grab -draw_mouse 0 -r 60 -s 1920x1080 -thread_queue_size 14000 -i :0.0+0,0 -f alsa -thread_queue_size 14000 -i plug:bsnoop -acodec aac -strict -2 -ar 44100 -b:a 128k -af aresample=async=1 -c:v h264_vaapi -vf format=nv12,hwupload,scale_vaapi=w=1920:h=1080 -attempt_recovery 1 -max_recovery_attempts 2 -drop_pkts_on_overflow 1 -video_size 1920x1080 -crf 19 -preset medium -maxrate 14000k -bufsize 14000k -r 60 -crf 25 -g 120 -tune zerolatency -f flv rtmp://[some_other_source]



The ffmpeg output is as follows :


2022-11-21 13:42:45.527 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption crf (Select the quality for constant quality mode) specified for output file #0 (rtmp://[some_other_sorce]) 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.
2022-11-21 13:42:45.527 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption tune (The metric that the encoder tunes for. Automatically chosen by the encoder by default) specified for output file #0 (rtmp://[some_other_source]) 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.
2022-11-21 13:42:45.527 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption preset (Encoding preset) specified for output file #0 (rtmp://relay.bingewave.com/live/e3057272-271d-40d5-90d1-f9065c5dfa37-broadcast?sign=1669642928-17aa73baeaedaad786140b5b2cca9d2b) 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.
2022-11-21 13:42:45.527 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption preset (Encoding preset) specified for output file #1 (rtmp://127.0.0.1:1935/live/e3057272-271d-40d5-90d1-f9065c5dfa37-broadcast?sign=1669642928-17aa73baeaedaad786140b5b2cca9d2b) 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.
2022-11-21 13:42:45.527 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption tune (The metric that the encoder tunes for. Automatically chosen by the encoder by default) specified for output file #1 (rtmp://127.0.0.1:1935/live/['for_reording']) 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.
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption crf (Select the quality for constant quality mode) specified for output file #1 (rtmp://127.0.0.1:1935/live/e3057272-271d-40d5-90d1-f9065c5dfa37-broadcast?sign=1669642928-17aa73baeaedaad786140b5b2cca9d2b) 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.
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream mapping:
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_vaapi))
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #0:0 -> #1:0 (rawvideo (native) -> h264 (h264_vaapi))
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #1:0 -> #1:1 (pcm_s16le (native) -> mp3 (libmp3lame))
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Press [q] to stop, [?] for help
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df06980] No quality level set; using default (20).
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df06980] Buffering settings are ignored in CQP RC mode.
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df06980] Driver does not support some wanted packed headers (wanted 0xd, found 0).
2022-11-21 13:42:45.550 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df06980] Driver does not support packed sequence headers, but a global header is requested.
2022-11-21 13:42:45.583 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df06980] No global header will be written: this may result in a stream which is not usable for some purposes (e.g. not muxable to some containers).
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df0a700] Driver does not support some wanted packed headers (wanted 0xd, found 0).
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df0a700] Driver does not support packed sequence headers, but a global header is requested.
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [h264_vaapi @ 0x55a02df0a700] No global header will be written: this may result in a stream which is not usable for some purposes (e.g. not muxable to some containers).
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Output #0, flv, to 'rtmp://relay.bingewave.com/live/[some_other_source]':
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Metadata:
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: encoder : Lavf59.27.100
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), vaapi(tv, progressive), 1920x1080, q=2-31, 60 fps, 1k tbn
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Metadata:
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: encoder : Lavc59.37.100 h264_vaapi
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Metadata:
2022-11-21 13:42:45.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: encoder : Lavc59.37.100 aac
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Output #1, flv, to 'rtmp://127.0.0.1:1935/live/e3057272-271d-40d5-90d1-f9065c5dfa37-broadcast?sign=1669642928-17aa73baeaedaad786140b5b2cca9d2b':
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Metadata:
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: encoder : Lavf59.27.100
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #1:0: Video: h264 (High) ([7][0][0][0] / 0x0007), vaapi(tv, progressive), 1920x1080, q=2-31, 15000 kb/s, 60 fps, 1k tbn
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Metadata:
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: encoder : Lavc59.37.100 h264_vaapi
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #1:1: Audio: mp3 ([2][0][0][0] / 0x0002), 48000 Hz, stereo, s16p
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Metadata:
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: encoder : Lavc59.37.100 libmp3lame
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: frame= 1 fps=0.0 q=-0.0 q=-0.0 size= 7kB time=00:00:00.06 bitrate= 875.5kbits/s speed=1.31x 
2022-11-21 13:42:46.584 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: frame= 31 fps=0.0 q=-0.0 q=-0.0 size= 281kB time=00:00:00.55 bitrate=4133.2kbits/s speed=1.01x 
2022-11-21 13:42:47.325 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: frame= 60 fps= 57 q=-0.0 q=-0.0 size= 546kB time=00:00:01.18 bitrate=3774.7kbits/s speed=1.12x 
2022-11-21 13:42:47.325 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: frame= 91 fps= 58 q=-0.0 q=-0.0 size= 828kB time=00:00:01.69 bitrate=4003.3kbits/s speed=1.08x 
2022-11-21 13:42:47.325 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [flv @ 0x55a02df10e00] Failed to update header with correct duration.
2022-11-21 13:42:47.325 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [flv @ 0x55a02df10e00] Failed to update header with correct filesize.
2022-11-21 13:42:47.325 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [flv @ 0x55a02df15500] Failed to update header with correct duration.
2022-11-21 13:42:47.325 INFO: [658] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [flv @ 0x55a02df15500] Failed to update header with correct filesize.



I've noticed there are several errors the headers going out. For VAAPI, how do I set resolution header ?


-
FFMPEG No such filter : 'format=nv12|vaapi,hwupload'
14 novembre 2022, par Devin DixonI'm on a AWS g4ad instance and I am trying to get hardware accelleration with the GPU to work. with ffmpeg. A base line test is this :


ffmpeg -y -vaapi_device /dev/dri/renderD128 -v info -thread_queue_size 10000 -i video.mp4 -c:v h264_vaapi -vf 'format=nv12|vaapi,hwupload' -crf 25 -tune zerolatency -g 120 -r 60 -pix_fmt yuv420p -preset faster -maxrate 14000k -bufsize 14000k -strict -2 -ar 44100 -b:a 128k -af aresample=async=1 -acodec aac file_out.mp4



The above works, GPU is installed and working correctly. In my actual use case, I am grabbing the screen from an X11Grab, which works without the GPU and normal libx264 but fails when I add try to use h264_vaapi. The command I use is below :


/usr/bin/ffmpeg -vaapi_device /dev/dri/renderD128 -y -v info -f x11grab -draw_mouse 0 -r 60 -s 1920x1080 -thread_queue_size 10000 -i :0.0+0,0 -f alsa -thread_queue_size 10000 -i plug:bsnoop -acodec aac -strict -2 -ar 44100 -b:a 128k -af aresample=async=1 -c:v h264_vaapi -vf 'format=nv12|vaapi,hwupload' -preset faster -maxrate 14000k -bufsize 14000k -pix_fmt yuv420p -r 60 -crf 25 -g 120 -tune zerolatency -f flv rtmp://[to_an_rtmp source]

And my output is this:

2022-11-14 02:08:30.928 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: ffmpeg version 5.1.2-0ubuntu1~18.04.sav1.1 Copyright (c) 2000-2022 the FFmpeg developers
2022-11-14 02:08:30.928 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: built with gcc 7 (Ubuntu 7.5.0-6ubuntu2~18.04.sav0)
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: configuration: --prefix=/usr --extra-version='0ubuntu1~18.04.sav1.1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-lcms2 --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libjxl --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-sndio --enable-pocketsphinx --enable-librsvg --enable-crystalhd --enable-libmfx --enable-libsvtav1 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libavutil 57. 28.100 / 57. 28.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libavcodec 59. 37.100 / 59. 37.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libavformat 59. 27.100 / 59. 27.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libavdevice 59. 7.100 / 59. 7.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libavfilter 8. 44.100 / 8. 44.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libswscale 6. 7.100 / 6. 7.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libswresample 4. 7.100 / 4. 7.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: libpostproc 56. 6.100 / 56. 6.100
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [x11grab @ 0x56155ee70ac0] Stream #0: not enough frames to estimate rate; consider increasing probesize
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Input #0, x11grab, from ':0.0+0,0':
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Duration: N/A, start: 1668391710.975066, bitrate: 3981312 kb/s
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 3981312 kb/s, 60 fps, 1000k tbr, 1000k tbn
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Guessed Channel Layout for Input Stream #1.0 : stereo
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Input #1, alsa, from 'plug:bsnoop':
2022-11-14 02:08:31.105 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Duration: N/A, start: 1668391710.731953, bitrate: 1536 kb/s
2022-11-14 02:08:31.106 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
2022-11-14 02:08:31.106 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption crf (Select the quality for constant quality mode) specified for output file #0 (rtmp://ingest.bingewave.com/live/ce98c9bb-78b0-4ee5-8a8e-af35160da695-broadcast?sign=1668996507-c340acfb5219383f660d41057a050de6) 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.
2022-11-14 02:08:31.106 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption preset (Encoding preset) specified for output file #0 (rtmp://ingest.bingewave.com/live/ce98c9bb-78b0-4ee5-8a8e-af35160da695-broadcast?sign=1668996507-c340acfb5219383f660d41057a050de6) 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.
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Codec AVOption tune (The metric that the encoder tunes for. Automatically chosen by the encoder by default) specified for output file #0 (rtmp://ingest.bingewave.com/live/ce98c9bb-78b0-4ee5-8a8e-af35160da695-broadcast?sign=1668996507-c340acfb5219383f660d41057a050de6) 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.
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream mapping:
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_vaapi))
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Press [q] to stop, [?] for help
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: [AVFilterGraph @ 0x56155ee5d880] No such filter: 'format=nv12|vaapi,hwupload'
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Error reinitializing filters!
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Failed to inject frame into filter network: Invalid argument
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Error while processing the decoded data for stream #0:0
2022-11-14 02:08:31.237 INFO: [557] LoggingUtils$Companion$OutputLogger$1.invoke$lambda-0#42: Conversion failed!
root@ip-172-31-90-180:~# 



I see that is failing because No such filter : 'format=nv12|vaapi,hwupload', which I don't get when I run the other command. What am I doing wrong here ?


-
Saving frames as JPG with FFMPEG (Visual Studio / C++)
10 novembre 2022, par Diego SatizabalI am trying to save all frames from a mp4 video in separate JPG files, I have a code that runs and actually saves something to JPG files but files are not recognized as images and nothing is showing.


Below my full code, I am using Visual Studio 2022 in Windows 11 and FFMPEG 5.1. The function that saves the images is save_frame_as_jpeg which is actually an adaption from the code provided here but changing the use of avcodec_encode_video2 for avcodec_send_frame/avcodec_receive_packet as indicated in the documentation.


I am obiously doing something wrong but cannot quite find it, BTW, I know that a simple command (ffmpeg -i input.mp4 -vf fps=1 vid_%d.png) will do this but I am requiring to do it by code.


Any help is appreciated, thanks in advance !


// FfmpegTests.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#pragma warning(disable : 4996)
extern "C"
{
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
 #include "libavfilter/avfilter.h"
 #include "libavutil/opt.h"
 #include "libavutil/avutil.h"
 #include "libavutil/error.h"
 #include "libavfilter/buffersrc.h"
 #include "libavfilter/buffersink.h"
 #include "libswscale/swscale.h"
}

#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avfilter.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "swscale.lib")

#include <cstdio>
#include <iostream>
#include <chrono>
#include <thread>


static AVFormatContext* fmt_ctx;
static AVCodecContext* dec_ctx;
AVFilterGraph* filter_graph;
AVFilterContext* buffersrc_ctx;
AVFilterContext* buffersink_ctx;
static int video_stream_index = -1;

const char* filter_descr = "scale=78:24,transpose=cclock";
static int64_t last_pts = AV_NOPTS_VALUE;

static int open_input_file(const char* filename)
{
 const AVCodec* dec;
 int ret;

 if ((ret = avformat_open_input(&fmt_ctx, filename, NULL, NULL)) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");
 return ret;
 }

 if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
 return ret;
 }

 /* select the video stream */
 ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &dec, 0);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file\n");
 return ret;
 }
 video_stream_index = ret;

 /* create decoding context */
 dec_ctx = avcodec_alloc_context3(dec);
 if (!dec_ctx)
 return AVERROR(ENOMEM);
 avcodec_parameters_to_context(dec_ctx, fmt_ctx->streams[video_stream_index]->codecpar);

 /* init the video decoder */
 if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot open video decoder\n");
 return ret;
 }

 return 0;
}

static int init_filters(const char* filters_descr)
{
 char args[512];
 int ret = 0;
 const AVFilter* buffersrc = avfilter_get_by_name("buffer");
 const AVFilter* buffersink = avfilter_get_by_name("buffersink");
 AVFilterInOut* outputs = avfilter_inout_alloc();
 AVFilterInOut* inputs = avfilter_inout_alloc();
 AVRational time_base = fmt_ctx->streams[video_stream_index]->time_base;
 enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };

 filter_graph = avfilter_graph_alloc();
 if (!outputs || !inputs || !filter_graph) {
 ret = AVERROR(ENOMEM);
 goto end;
 }

 /* buffer video source: the decoded frames from the decoder will be inserted here. */
 snprintf(args, sizeof(args),
 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
 dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
 time_base.num, time_base.den,
 dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);

 ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
 args, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
 goto end;
 }

 /* buffer video sink: to terminate the filter chain. */
 ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
 NULL, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
 goto end;
 }

 ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
 goto end;
 }

 outputs->name = av_strdup("in");
 outputs->filter_ctx = buffersrc_ctx;
 outputs->pad_idx = 0;
 outputs->next = NULL;

 inputs->name = av_strdup("out");
 inputs->filter_ctx = buffersink_ctx;
 inputs->pad_idx = 0;
 inputs->next = NULL;

 if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
 &inputs, &outputs, NULL)) < 0)
 goto end;

 if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
 goto end;

end:
 avfilter_inout_free(&inputs);
 avfilter_inout_free(&outputs);

 return ret;
}

static void display_frame(const AVFrame* frame, AVRational time_base)
{
 int x, y;
 uint8_t* p0, * p;
 int64_t delay;

 if (frame->pts != AV_NOPTS_VALUE) {
 if (last_pts != AV_NOPTS_VALUE) {
 /* sleep roughly the right amount of time;
 * usleep is in microseconds, just like AV_TIME_BASE. */
 AVRational timeBaseQ;
 timeBaseQ.num = 1;
 timeBaseQ.den = AV_TIME_BASE;

 delay = av_rescale_q(frame->pts - last_pts, time_base, timeBaseQ);
 if (delay > 0 && delay < 1000000)
 std::this_thread::sleep_for(std::chrono::microseconds(delay));
 }
 last_pts = frame->pts;
 }

 /* Trivial ASCII grayscale display. */
 p0 = frame->data[0];
 puts("\033c");
 for (y = 0; y < frame->height; y++) {
 p = p0;
 for (x = 0; x < frame->width; x++)
 putchar(" .-+#"[*(p++) / 52]);
 putchar('\n');
 p0 += frame->linesize[0];
 }
 fflush(stdout);
}

int save_frame_as_jpeg(AVCodecContext* pCodecCtx, AVFrame* pFrame, int FrameNo) {
 int ret = 0;

 const AVCodec* jpegCodec = avcodec_find_encoder(AV_CODEC_ID_JPEG2000);
 if (!jpegCodec) {
 return -1;
 }
 AVCodecContext* jpegContext = avcodec_alloc_context3(jpegCodec);
 if (!jpegContext) {
 return -1;
 }

 jpegContext->pix_fmt = pCodecCtx->pix_fmt;
 jpegContext->height = pFrame->height;
 jpegContext->width = pFrame->width;
 jpegContext->time_base = AVRational{ 1,10 };

 ret = avcodec_open2(jpegContext, jpegCodec, NULL);
 if (ret < 0) {
 return ret;
 }
 FILE* JPEGFile;
 char JPEGFName[256];

 AVPacket packet;
 packet.data = NULL;
 packet.size = 0;
 av_init_packet(&packet);

 int gotFrame;

 ret = avcodec_send_frame(jpegContext, pFrame);
 if (ret < 0) {
 return ret;
 }

 ret = avcodec_receive_packet(jpegContext, &packet);
 if (ret < 0) {
 return ret;
 }

 sprintf(JPEGFName, "c:\\folder\\dvr-%06d.jpg", FrameNo);
 JPEGFile = fopen(JPEGFName, "wb");
 fwrite(packet.data, 1, packet.size, JPEGFile);
 fclose(JPEGFile);

 av_packet_unref(&packet);
 avcodec_close(jpegContext);
 return 0;
}

int main(int argc, char** argv)
{
 AVFrame* frame;
 AVFrame* filt_frame;
 AVPacket* packet;
 int ret;

 if (argc != 2) {
 fprintf(stderr, "Usage: %s file\n", argv[0]);
 exit(1);
 }

 frame = av_frame_alloc();
 filt_frame = av_frame_alloc();
 packet = av_packet_alloc();

 if (!frame || !filt_frame || !packet) {
 fprintf(stderr, "Could not allocate frame or packet\n");
 exit(1);
 }

 if ((ret = open_input_file(argv[1])) < 0)
 goto end;
 if ((ret = init_filters(filter_descr)) < 0)
 goto end;

 while (true)
 {
 if ((ret = av_read_frame(fmt_ctx, packet)) < 0)
 break;

 if (packet->stream_index == video_stream_index) {
 ret = avcodec_send_packet(dec_ctx, packet);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
 break;
 }

 while (ret >= 0)
 {
 ret = avcodec_receive_frame(dec_ctx, frame);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
 break;
 }
 else if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while receiving a frame from the decoder\n");
 goto end;
 }

 frame->pts = frame->best_effort_timestamp;

 /* push the decoded frame into the filtergraph */
 if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
 break;
 }

 /* pull filtered frames from the filtergraph */
 while (1) {
 ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 break;
 if (ret < 0)
 goto end;
 display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base);
 av_frame_unref(filt_frame);
 
 ret = save_frame_as_jpeg(dec_ctx, frame, dec_ctx->frame_number);
 if (ret < 0)
 goto end;
 }
 av_frame_unref(frame);
 }
 }
 av_packet_unref(packet);
 }

end:
 avfilter_graph_free(&filter_graph);
 avcodec_free_context(&dec_ctx);
 avformat_close_input(&fmt_ctx);
 av_frame_free(&frame);
 av_frame_free(&filt_frame);
 av_packet_free(&packet);

 if (ret < 0 && ret != AVERROR_EOF) {
 char errBuf[AV_ERROR_MAX_STRING_SIZE]{0};
 int res = av_strerror(ret, errBuf, AV_ERROR_MAX_STRING_SIZE);
 fprintf(stderr, "Error: %s\n", errBuf);
 exit(1);
 }

 exit(0);
}
</thread></chrono></iostream></cstdio>