convert h.264 avi container to mp4 with ffmpeg - ffmpeg

I'd like to convert my h.264 avi container to a mp4 container with ffmpeg. I've found this works:
./ffmpeg -i myfile.avi -vcodec copy myfile.mp4
ffmpeg version N-51169-gcedf276 Copyright (c) 2000-2013 the FFmpeg developers
built on Mar 21 2013 05:12:00 with gcc 4.6 (Debian 4.6.3-1)
configuration: --prefix=/root/ffmpeg-static/32bit --arch=x86_32 --extra-cflags='-m32 -I/root/ffmpeg-static/32bit/include -static' --extra-ldflags='-m32 -L/root/ffmpeg-static/32bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
libavutil 52. 22.100 / 52. 22.100
libavcodec 55. 1.100 / 55. 1.100
libavformat 55. 0.100 / 55. 0.100
libavdevice 55. 0.100 / 55. 0.100
libavfilter 3. 48.100 / 3. 48.100
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[avi # 0x9fff660] non-interleaved AVI
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'myfile.avi':
Metadata:
encoder : Lavf52.64.2
Duration: 00:00:10.40, start: 0.000000, bitrate: 409 kb/s
Stream #0:0: Video: h264 (Baseline) (H264 / 0x34363248), yuvj420p, 640x480, 10 fps, 10 tbr, 10 tbn, 30 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
Output #0, mp4, to 'myfile.mp4':
Metadata:
encoder : Lavf55.0.100
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 640x480, q=2-31, 10 fps, 10240 tbn, 10 tbc
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 8000 Hz, mono, s16, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (pcm_s16le -> libvo_aacenc)
Press [q] to stop, [?] for help
[mp4 # 0xa006ea0] pts has no value
Last message repeated 100 times
frame= 101 fps=0.0 q=-1.0 Lsize= 350kB time=00:00:11.06 bitrate= 259.3kbits/s
video:332kB audio:15kB subtitle:0 global headers:0kB muxing overhead 0.926809%
This generates a file that I can play with the HTML5 video player but for legacy browsers I'd like to use a flash player (Flowplayer). The file doesn't play with Flowplayer, in fact it causes it to crash.
However if I use:
./ffmpeg -i myfile.avi myfile2.mp4
ffmpeg version N-51169-gcedf276 Copyright (c) 2000-2013 the FFmpeg developers
built on Mar 21 2013 05:12:00 with gcc 4.6 (Debian 4.6.3-1)
configuration: --prefix=/root/ffmpeg-static/32bit --arch=x86_32 --extra-cflags='-m32 -I/root/ffmpeg-static/32bit/include -static' --extra-ldflags='-m32 -L/root/ffmpeg-static/32bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
libavutil 52. 22.100 / 52. 22.100
libavcodec 55. 1.100 / 55. 1.100
libavformat 55. 0.100 / 55. 0.100
libavdevice 55. 0.100 / 55. 0.100
libavfilter 3. 48.100 / 3. 48.100
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[avi # 0x9b02660] non-interleaved AVI
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'myfile.avi':
Metadata:
encoder : Lavf52.64.2
Duration: 00:00:10.40, start: 0.000000, bitrate: 409 kb/s
Stream #0:0: Video: h264 (Baseline) (H264 / 0x34363248), yuvj420p, 640x480, 10 fps, 10 tbr, 10 tbn, 30 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
No pixel format specified, yuvj420p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 # 0x9b065a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
[libx264 # 0x9b065a0] profile High, level 2.2
[libx264 # 0x9b065a0] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'myfile2.mp4':
Metadata:
encoder : Lavf55.0.100
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 640x480, q=-1--1, 10240 tbn, 10 tbc
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 8000 Hz, mono, s16, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (pcm_s16le -> libvo_aacenc)
Press [q] to stop, [?] for help
frame= 47 fps=0.0 q=25.0 size= 21kB time=00:00:04.40 bitrate= 39.9kbits/s dup=3 dropframe= 59 fps= 56 q=25.0 size= 56kB time=00:00:05.68 bitrate= 80.2kbits/s dup=3 dropframe= 71 fps= 45 q=25.0 size= 89kB time=00:00:06.84 bitrate= 106.9kbits/s dup=3 dropframe= 83 fps= 40 q=25.0 size= 124kB time=00:00:08.12 bitrate= 124.9kbits/s dup=3 dropframe= 94 fps= 36 q=25.0 size= 157kB time=00:00:09.14 bitrate= 140.4kbits/s dup=4 dropframe= 105 fps= 23 q=25.0 Lsize= 309kB time=00:00:11.06 bitrate= 228.8kbits/s dup=4 drop=0
video:291kB audio:15kB subtitle:0 global headers:0kB muxing overhead 1.108651%
[libx264 # 0x9b065a0] frame I:1 Avg QP:17.65 size: 12772
[libx264 # 0x9b065a0] frame P:94 Avg QP:19.46 size: 2868
[libx264 # 0x9b065a0] frame B:10 Avg QP:21.58 size: 1464
[libx264 # 0x9b065a0] consecutive B-frames: 82.9% 13.3% 0.0% 3.8%
[libx264 # 0x9b065a0] mb I I16..4: 16.6% 66.3% 17.1%
[libx264 # 0x9b065a0] mb P I16..4: 4.2% 6.3% 0.5% P16..4: 27.0% 9.5% 5.1% 0.0% 0.0% skip:47.4%
[libx264 # 0x9b065a0] mb B I16..4: 0.8% 1.0% 0.0% B16..8: 39.1% 4.6% 0.5% direct: 2.4% skip:51.7% L0:39.8% L1:56.4% BI: 3.9%
[libx264 # 0x9b065a0] 8x8 transform intra:58.0% inter:74.7%
[libx264 # 0x9b065a0] coded y,uvDC,uvAC intra: 47.3% 0.0% 0.0% inter: 16.6% 0.0% 0.0%
[libx264 # 0x9b065a0] i16 v,h,dc,p: 29% 19% 10% 42%
[libx264 # 0x9b065a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 21% 29% 2% 3% 4% 4% 3% 3%
[libx264 # 0x9b065a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 28% 18% 2% 3% 3% 3% 2% 2%
[libx264 # 0x9b065a0] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 # 0x9b065a0] Weighted P-Frames: Y:5.3% UV:0.0%
[libx264 # 0x9b065a0] ref P L0: 67.9% 12.0% 12.6% 6.8% 0.6%
[libx264 # 0x9b065a0] ref B L0: 76.9% 23.1%
[libx264 # 0x9b065a0] ref B L1: 99.7% 0.3%
[libx264 # 0x9b065a0] kb/s:226.31
This works great. But the timing is quite different not to mention CPU cycles. The first command is measured in milli-secs while the second can take quite some time (~5-40secs).
Is there another way I can convert the avi to a mp4 container quickly? Ideally by re-muxing as opposed to re-encoding.
EDIT
I'm using this right now which I find to be the fastest for re-encoding. But again I'd rather not do this. I just want to re-mux the code.
ffmpeg -loglevel quiet -i myfile.avi -vcodec libx264 -profile:v baseline -preset ultrafast myfile.mp4

I wouldn't have done it differently than you already did. I tried to remux the file with ffmpeg-1.2 on OS X 10.7:
ffmpeg --info
ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
built on Apr 8 2013 02:39:03 with Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
I tried your commands and explicitly
ffmpeg -i myfile.avi -vcodec copy -acodec copy out.mp4
But I always got the following errors:
ffmpeg -i myfile.avi -vcodec copy -acodec copy out.mp4
ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
built on Apr 8 2013 02:39:03 with Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[avi # 0x7f9ef981ae00] non-interleaved AVI
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'myfile.avi':
Metadata:
encoder : Lavf52.64.2
Duration: 00:00:10.40, start: 0.000000, bitrate: 409 kb/s
Stream #0:0: Video: h264 (Baseline) (H264 / 0x34363248), yuvj420p, 640x480, 10 fps, 10 tbr, 10 tbn, 30 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
[mp4 # 0x7f9ef991ac00] Tag [1][0][0][0]/0x00000001 incompatible with output codec id '65536' ([0][0][0][0])
Output #0, mp4, to 'out.mp4':
Metadata:
encoder : Lavf52.64.2
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 640x480, q=2-31, 10 fps, 90k tbn, 10 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
So I did a quick research for the error number and found out pcm_s16le isn't compatible with mp4. See this bug report on the ffmpeg tracker.
This would possibly explain the different results with both of your commands - although it's strange that it did not yield an error in your case (old ffmpeg snapshot?).
So I guess the solution could/would be to provide a different audio codec from the beginning or to convert the audio track to a different codec. As a quick test I tried:
ffmpeg -i myfile.avi -vcodec copy -acodec mp2 out.mp4
The output file was written immediately to disk - no errors were yielded. Unfortunately I don't have the possibility to verify the result with a flash player.

Related

ffmpeg keep framerate as source

I am trying to use ffmpeg to overlay a video on a backgroud image. But the output video has different framerate(25) and length compared to the source video, I guess this is causing the tiny out-of-sync between video and audio in the output. How can I tune the command to keep the framerate same as source?
ffmpeg -i crop.mp4
ffmpeg version 4.3.1-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'crop.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.76.100
Duration: 00:02:26.10, start: 0.000000, bitrate: 1378 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1080x810, 1240 kb/s, 31.25 fps, 31.25 tbr, 16k tbn, 62.50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Here is the command
/data/ffmpeg-4.4-amd64-static/ffmpeg -i background_image_crop.png -i crop.mp4 -filter_complex "[0:v][1:v]overlay=x=0:y=H/2-h/2" -c:a copy output.mp4
ffmpeg version 4.4-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Input #0, png_pipe, from 'background_image_crop.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, rgb24(pc), 1080x1920, 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'crop.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.76.100
Duration: 00:02:26.10, start: 0.000000, bitrate: 1378 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1080x810, 1240 kb/s, 31.25 fps, 31.25 tbr, 16k tbn, 62.50 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 (png) -> overlay:main
Stream #1:0 (h264) -> overlay:overlay
overlay -> Stream #0:0 (libx264)
Stream #1:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 # 0x57da140] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x57da140] profile High, level 4.0, 4:2:0, 8-bit
[libx264 # 0x57da140] 264 - core 161 r3048 b86ae3c - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=60 lookahead_threads=10 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
Metadata:
encoder : Lavf58.76.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, progressive), 1080x1920, q=2-31, 25 fps, 12800 tbn (default)
Metadata:
encoder : Lavc58.134.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
frame= 3653 fps= 96 q=-1.0 Lsize= 24563kB time=00:02:26.07 bitrate=1377.5kbits/s dup=0 drop=911 speed=3.85x
video:22143kB audio:2299kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.492343%
[libx264 # 0x57da140] frame I:16 Avg QP:14.36 size:125240
[libx264 # 0x57da140] frame P:989 Avg QP:17.65 size: 13266
[libx264 # 0x57da140] frame B:2648 Avg QP:25.21 size: 2851
[libx264 # 0x57da140] consecutive B-frames: 1.1% 4.3% 7.6% 87.1%
[libx264 # 0x57da140] mb I I16..4: 11.1% 72.4% 16.4%
[libx264 # 0x57da140] mb P I16..4: 2.6% 7.4% 0.6% P16..4: 14.9% 4.4% 2.3% 0.0% 0.0% skip:67.9%
[libx264 # 0x57da140] mb B I16..4: 0.3% 0.6% 0.0% B16..8: 13.8% 1.0% 0.1% direct: 0.4% skip:83.8% L0:43.9% L1:53.9% BI: 2.2%
[libx264 # 0x57da140] 8x8 transform intra:69.0% inter:87.7%
[libx264 # 0x57da140] coded y,uvDC,uvAC intra: 39.2% 62.5% 18.5% inter: 2.7% 4.8% 0.0%
[libx264 # 0x57da140] i16 v,h,dc,p: 33% 27% 8% 32%
[libx264 # 0x57da140] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 19% 21% 4% 5% 5% 4% 5% 3%
[libx264 # 0x57da140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 20% 10% 5% 8% 8% 6% 6% 3%
[libx264 # 0x57da140] i8c dc,h,v,p: 49% 19% 25% 7%
[libx264 # 0x57da140] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 # 0x57da140] ref P L0: 66.6% 10.3% 18.0% 5.1%
[libx264 # 0x57da140] ref B L0: 91.4% 7.2% 1.4%
[libx264 # 0x57da140] ref B L1: 96.8% 3.2%
[libx264 # 0x57da140] kb/s:1241.39
For your example is 31.25 fps, Richard use parameter -r for fps value in the start of code, like this
ffmpeg -r 31.25 -i background_image_crop.png -i crop.mp4 -filter_complex "[0:v][1:v]overlay=x=0:y=H/2-h/2" -c:a copy -preset ultrafast -movflags -faststart output.mp4
(I add -movflags -faststart for the video charge fast, and preset ultrafast to do all fast, only for this example)
I has probed this example getting the next data:
ffmpeg -i output.mp4
Duration: 00:06:33.39, start: 0.000000, bitrate: 1523 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1421 kb/s, 31.25 fps, 31.25 tbr, 16k tbn, 62.50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)
Metadata:
handler_name : SoundHandler

How to fix ffmpeg complex filters "Invalid stream specifier" [duplicate]

This question already has answers here:
FFmpeg filter_complex concat gives only first input on crop
(1 answer)
Problems building Image slideshow with sliding transition using ffmpeg
(1 answer)
ffmpeg: chain of multiple filter_complex, re-using intermediate output stream
(1 answer)
Closed 3 years ago.
I'm attempting to scale and blur (sections of) a video with ffmpeg complex filters. This has actually been working in production for years.
I'm now running a newer build of ffmpeg on Ubuntu 18.04 and getting an error relating to the filters where the same command works fine on Ubuntu 16.04's ffmpeg against the same video.
Specifically, I'm seeing the following error:
mov,mp4,m4a,3gp,3g2,mj2 # 0x56055a5902c0] Invalid stream specifier: vs0.
Last message repeated 1 times
Stream specifier 'vs0' in filtergraph description ... matches no streams.
Has something about the complex filter API changed that would make this same input invalid in a newer version of ffmpeg?
The command in question is just running the following in a Bash terminal.
ffmpeg -ss 60 -i ~/test.mp4 -y -filter_complex "[0:v]scale=-2:'min(320,ih)'[vs0];[vs0]crop=in_w/9:in_h/2:0:0,boxblur=5:1:cr=3:ar=3[b0];[vs0]crop=in_w/9:in_h/2:in_w-out_w:0,boxblur=5:1:cr=3:ar=3[b1];[vs0]crop=(in_w-2*in_w/9):in_h/20:in_w/9:0,boxblur=5:1:cr=3:ar=3[b2];[vs0][b0]overlay=0:0[ovr0];[ovr0][b1]overlay=main_w-overlay_w:0[ovr1];[ovr1][b2]overlay=main_w/9:0[vs1]" -map [vs1] -an -ac 2 -b:a 128k -acodec aac -b:v 1024k -r 30 -vcodec libx264 -t 300 -y -preset slow -movflags faststart -pix_fmt yuv420p -f mp4 ~/out.mp4
If we break up the complex filter statement, it looks like:
[0:v]scale=-2:'min(320,ih)'[vs0];
[vs0]crop=in_w/9:in_h/2:0:0,boxblur=5:1:cr=3:ar=3[b0];
[vs0]crop=in_w/9:in_h/2:in_w-out_w:0,boxblur=5:1:cr=3:ar=3[b1];
[vs0]crop=(in_w-2*in_w/9):in_h/20:in_w/9:0,boxblur=5:1:cr=3:ar=3[b2];
[vs0][b0]overlay=0:0[ovr0];[ovr0][b1]overlay=main_w-overlay_w:0[ovr1];
[ovr1][b2]overlay=main_w/9:0[vs1]
On ffmpeg version N-86980-g62b7553 (Ubuntu 16.04), everything works great as it has done for years.
$ ffmpeg -ss 60 -i ~/test.mp4 -y -filter_complex "[0:v]scale=-2:'min(320,ih)'[vs0];[vs0]crop=in_w/9:in_h/2:0:0,boxblur=5:1:cr=3:ar=3[b0];[vs0]crop=in_w/9:in_h/2:in_w-out_w:0,boxblur=5:1:cr=3:ar=3[b1];[vs0]crop=(in_w-2*in_w/9):in_h/20:in_w/9:0,boxblur=5:1:cr=3:ar=3[b2];[vs0][b0]overlay=0:0[ovr0];[ovr0][b1]overlay=main_w-overlay_w:0[ovr1];[ovr1][b2]overlay=main_w/9:0[vs1]" -map [vs1] -an -ac 2 -b:a 128k -acodec aac -b:v 1024k -r 30 -vcodec libx264 -t 300 -y -preset slow -movflags faststart -pix_fmt yuv420p -f mp4 ~/out.mp4
ffmpeg version N-86980-g62b7553 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-nonfree
libavutil 55. 73.100 / 55. 73.100
libavcodec 57.102.100 / 57.102.100
libavformat 57. 76.100 / 57. 76.100
libavdevice 57. 7.100 / 57. 7.100
libavfilter 6. 98.100 / 6. 98.100
libswscale 4. 7.102 / 4. 7.102
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/cmaier/test.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.76.100
Duration: 00:10:00.00, start: 0.000000, bitrate: 1036 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 768x480, 1033 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream mapping:
Stream #0:0 (h264) -> scale
Stream #0:0 (h264) -> crop
Stream #0:0 (h264) -> crop
Stream #0:0 (h264) -> overlay:main
overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[libx264 # 0x27b2ca0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 # 0x27b2ca0] profile High, level 3.1
[libx264 # 0x27b2ca0] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=abr mbtree=1 bitrate=1024 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/home/cmaier/out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.76.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 768x480, q=-1--1, 1024 kb/s, 30 fps, 15360 tbn, 30 tbc (default)
Metadata:
encoder : Lavc57.102.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/1024000 buffer size: 0 vbv_delay: -1
[mp4 # 0x27b5a60] Starting second pass: moving the moov atom to the beginning of the file3.9x
frame= 9000 fps=117 q=-1.0 Lsize= 37827kB time=00:04:59.90 bitrate=1033.3kbits/s speed= 3.9x
video:37721kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.282333%
[libx264 # 0x27b2ca0] frame I:36 Avg QP:15.21 size: 50944
[libx264 # 0x27b2ca0] frame P:2723 Avg QP:20.12 size: 9593
[libx264 # 0x27b2ca0] frame B:6241 Avg QP:24.23 size: 1710
[libx264 # 0x27b2ca0] consecutive B-frames: 3.6% 6.9% 14.5% 75.0%
[libx264 # 0x27b2ca0] mb I I16..4: 17.3% 58.5% 24.2%
[libx264 # 0x27b2ca0] mb P I16..4: 0.5% 4.4% 0.9% P16..4: 31.1% 20.7% 12.1% 0.0% 0.0% skip:30.3%
[libx264 # 0x27b2ca0] mb B I16..4: 0.0% 0.3% 0.1% B16..8: 28.9% 5.5% 1.1% direct: 1.1% skip:63.1% L0:37.5% L1:52.6% BI: 9.9%
[libx264 # 0x27b2ca0] final ratefactor: 19.69
[libx264 # 0x27b2ca0] 8x8 transform intra:72.8% inter:68.3%
[libx264 # 0x27b2ca0] direct mvs spatial:99.9% temporal:0.1%
[libx264 # 0x27b2ca0] coded y,uvDC,uvAC intra: 74.5% 73.0% 30.4% inter: 13.0% 10.7% 0.2%
[libx264 # 0x27b2ca0] i16 v,h,dc,p: 49% 30% 3% 17%
[libx264 # 0x27b2ca0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 7% 14% 11% 7% 11% 8% 19% 8% 15%
[libx264 # 0x27b2ca0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 9% 13% 5% 8% 14% 10% 17% 9% 16%
[libx264 # 0x27b2ca0] i8c dc,h,v,p: 42% 29% 15% 15%
[libx264 # 0x27b2ca0] Weighted P-Frames: Y:7.4% UV:2.9%
[libx264 # 0x27b2ca0] ref P L0: 59.2% 20.2% 11.5% 3.7% 4.3% 1.0% 0.1%
[libx264 # 0x27b2ca0] ref B L0: 87.5% 8.8% 2.7% 1.0%
[libx264 # 0x27b2ca0] ref B L1: 96.5% 3.5%
[libx264 # 0x27b2ca0] kb/s:1030.01
On ffmpeg version N-93862-gf49cec2 (Ubuntu 18.04), the command fails immediately.
# ffmpeg -ss 60 -i ~/test.mp4 -y -filter_complex "[0:v]scale=-2:'min(320,ih)'[vs0];[vs0]crop=in_w/9:in_h/2:0:0,boxblur=5:1:cr=3:ar=3[b0];[vs0]crop=in_w/9:in_h/2:in_w-out_w:0,boxblur=5:1:cr=3:ar=3[b1];[vs0]crop=(in_w-2*in_w/9):in_h/20:in_w/9:0,boxblur=5:1:cr=3:ar=3[b2];[vs0][b0]overlay=0:0[ovr0];[ovr0][b1]overlay=main_w-overlay_w:0[ovr1];[ovr1][b2]overlay=main_w/9:0[vs1]" -map [vs1] -an -ac 2 -b:a 128k -acodec aac -b:v 1024k -r 30 -vcodec libx264 -t 300 -y -preset slow -movflags faststart -pix_fmt yuv420p -f mp4 ~/out.mp4
ffmpeg version N-93862-gf49cec2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04)
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-nonfree
libavutil 56. 27.100 / 56. 27.100
libavcodec 58. 52.101 / 58. 52.101
libavformat 58. 27.103 / 58. 27.103
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 53.100 / 7. 53.100
libswscale 5. 4.101 / 5. 4.101
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/root/test.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.76.100
Duration: 00:10:00.00, start: 0.000000, bitrate: 1036 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 768x480, 1033 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
[mov,mp4,m4a,3gp,3g2,mj2 # 0x56055a5902c0] Invalid stream specifier: vs0.
Last message repeated 1 times
Stream specifier 'vs0' in filtergraph description [0:v]scale=-2:'min(320,ih)'[vs0];[vs0]crop=in_w/9:in_h/2:0:0,boxblur=5:1:cr=3:ar=3[b0];[vs0]crop=in_w/9:in_h/2:in_w-out_w:0,boxblur=5:1:cr=3:ar=3[b1];[vs0]crop=(in_w-2*in_w/9):in_h/20:in_w/9:0,boxblur=5:1:cr=3:ar=3[b2];[vs0][b0]overlay=0:0[ovr0];[ovr0][b1]overlay=main_w-overlay_w:0[ovr1];[ovr1][b2]overlay=main_w/9:0[vs1] matches no streams.

Video becomes choppy when the order in the hstack filter is changed

I have a FFmpeg command wherein I am merging 2 videos side by side using hstack filter. When I place first video on the right hand side and second video on the left hand side, the final merged video is perfect in quality and plays smoothly.
However, when I swap the order in hstack filter, the final video is very choppy.
Can someone please let me know the issue in this command? Many thanks in advance.
Also, the file size of the non working file is almost double than that of working file. Can you explain why?
Here is the working command:
ffmpeg -i 1_a.opus -i 2_a.opus -itsoffset 0.024 -i 1_v.mp4 -itsoffset 0.113 -i 2_v.mp4 -filter_complex "[1:a]adelay=15646|15646[a1]; [0:a][a1]amix; [3:v]trim=0:15.646,geq=0:128:128[silence]; [3:v]fifo[3v]; [silence][3v]concat[3_v_silence]; [3_v_silence][2:v]hstack" -preset ultrafast -y n_m_bars_try2.mp4
output:
ffmpeg version 4.0.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, ogg, from '1_a.opus':
Duration: 00:01:03.82, start: -0.020000, bitrate: 37 kb/s
Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
Input #1, ogg, from '2_a.opus':
Duration: 00:00:52.40, start: -0.020000, bitrate: 44 kb/s
Stream #1:0: Audio: opus, 48000 Hz, stereo, fltp
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '1_v.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:01:03.85, start: 0.000000, bitrate: 2644 kb/s
Stream #2:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 2633 kb/s, 333 fps, 333 tbr, 10656 tbn, 666 tbc (default)
Metadata:
handler_name : VideoHandler
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '2_v.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:00:52.32, start: 0.000000, bitrate: 861 kb/s
Stream #3:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 860 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream mapping:
Stream #0:0 (opus) -> amix:input0
Stream #1:0 (opus) -> adelay
Stream #2:0 (h264) -> hstack:input1
Stream #3:0 (h264) -> trim
Stream #3:0 (h264) -> fifo
amix -> Stream #0:0 (aac)
hstack -> Stream #0:1 (libx264)
Press [q] to stop, [?] for help
[libx264 # 0x528d600] using SAR=1/1
[libx264 # 0x528d600] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle
[libx264 # 0x528d600] profile Constrained Baseline, level 3.1
[libx264 # 0x528d600] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'navid_mayank_bars_try2.mp4':
Metadata:
encoder : Lavf58.12.100
Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
encoder : Lavc58.18.100 aac
Stream #0:1: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x480 [SAR 1:1 DAR 8:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
encoder : Lavc58.18.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 1704 fps= 42 q=-1.0 Lsize= 14440kB time=00:01:08.12 bitrate=1736.5kbits/s dup=3 drop=21229 speed=1.69x
video:13448kB audio:953kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.269503%
[aac # 0x52b8680] Qavg: 22255.799
[libx264 # 0x528d600] frame I:7 Avg QP:16.29 size: 46284
[libx264 # 0x528d600] frame P:1697 Avg QP:18.36 size: 7924
[libx264 # 0x528d600] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 # 0x528d600] mb P I16..4: 1.8% 0.0% 0.0% P16..4: 31.0% 0.0% 0.0% 0.0% 0.0% skip:67.2%
[libx264 # 0x528d600] coded y,uvDC,uvAC intra: 29.9% 59.3% 17.5% inter: 13.4% 24.6% 0.8%
[libx264 # 0x528d600] i16 v,h,dc,p: 36% 29% 18% 17%
[libx264 # 0x528d600] i8c dc,h,v,p: 42% 25% 21% 11%
[libx264 # 0x528d600] kb/s:1616.23
Non working command:
ffmpeg -i 1_a.opus -i 2_a.opus -itsoffset 0.024 -i 1_v.mp4 -itsoffset 0.113 -i 2_v.mp4 -filter_complex "[1:a]adelay=15646|15646[a1]; [0:a][a1]amix; [3:v]trim=0:15.646,geq=0:128:128[silence]; [3:v]fifo[3v]; [silence][3v]concat[3_v_silence]; [2:v][3_v_silence]hstack" -preset ultrafast -y m_n_bars_try2.mp4
output:
ffmpeg version 4.0.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, ogg, from '1_a.opus':
Duration: 00:01:03.82, start: -0.020000, bitrate: 37 kb/s
Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
Input #1, ogg, from '2_a.opus':
Duration: 00:00:52.40, start: -0.020000, bitrate: 44 kb/s
Stream #1:0: Audio: opus, 48000 Hz, stereo, fltp
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '1_v.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:01:03.85, start: 0.000000, bitrate: 2644 kb/s
Stream #2:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 2633 kb/s, 333 fps, 333 tbr, 10656 tbn, 666 tbc (default)
Metadata:
handler_name : VideoHandler
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '2_v.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:00:52.32, start: 0.000000, bitrate: 861 kb/s
Stream #3:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 860 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream mapping:
Stream #0:0 (opus) -> amix:input0
Stream #1:0 (opus) -> adelay
Stream #2:0 (h264) -> hstack:input0
Stream #3:0 (h264) -> trim
Stream #3:0 (h264) -> fifo
amix -> Stream #0:0 (aac)
hstack -> Stream #0:1 (libx264)
Press [q] to stop, [?] for help
[libx264 # 0x6d21600] using SAR=1/1
[libx264 # 0x6d21600] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle
[libx264 # 0x6d21600] profile Constrained Baseline, level 5.1
[libx264 # 0x6d21600] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'mayank_navid_bars_try2.mp4':
Metadata:
encoder : Lavf58.12.100
Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
encoder : Lavc58.18.100 aac
Stream #0:1: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x480 [SAR 1:1 DAR 8:3], q=-1--1, 333 fps, 10656 tbn, 333 tbc (default)
Metadata:
encoder : Lavc58.18.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Past duration 0.999992 too large
Last message repeated 12 times
More than 1000 frames duplicated 33280kB time=00:01:08.03 bitrate=4007.4kbits/s dup=982 drop=1590 speed=0.536x
frame=22679 fps=177 q=-1.0 Lsize= 33892kB time=00:01:08.10 bitrate=4076.9kbits/s dup=1339 drop=1590 speed=0.531x
video:32804kB audio:953kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.401324%
[aac # 0x6d4c680] Qavg: 22255.799
[libx264 # 0x6d21600] frame I:91 Avg QP:15.31 size: 51639
[libx264 # 0x6d21600] frame P:22588 Avg QP:18.24 size: 1279
[libx264 # 0x6d21600] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 # 0x6d21600] mb P I16..4: 0.2% 0.0% 0.0% P16..4: 13.0% 0.0% 0.0% 0.0% 0.0% skip:86.8%
[libx264 # 0x6d21600] coded y,uvDC,uvAC intra: 44.9% 54.0% 29.9% inter: 2.0% 10.9% 0.1%
[libx264 # 0x6d21600] i16 v,h,dc,p: 45% 24% 13% 18%
[libx264 # 0x6d21600] i8c dc,h,v,p: 51% 20% 18% 11%
[libx264 # 0x6d21600] kb/s:3945.79
One of your videos is 333 fps and the other is 25. The order in which you apply them affects the frame rate of the output file. 25 is much easier to output than 333. Try adding '-r pal' just before declaring your output file.

ffmpeg concat last image duration incorrect

Here is my png.txt file:
file '01.png'
duration 92
file '02.png'
duration 46
file '03.png'
duration 67
file '04.png'
duration 62
file '05.png'
duration 57
file '06.png'
duration 3
file '06.png'
mp3 duration = 00:05:28 (total of above)
And here is the line:
ffmpeg -f concat -i png.txt -vsync vfr -i 20170817.mp3 -c:a aac -s 1280x720 -c:v libx264 -pix_fmt yuv420p -shortest 20170817.mp4
And here is the output:
ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.42)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, concat, from 'png.txt':
Duration: 00:05:27.00, start: 0.000000, bitrate: 0 kb/s
Stream #0:0: Video: png, rgba(pc), 1280x720 [SAR 2835:2835 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Input #1, mp3, from '20170817.mp3':
Metadata:
encoder : Lavf57.71.100
Duration: 00:05:28.10, start: 0.069063, bitrate: 24 kb/s
Stream #1:0: Audio: mp3, 16000 Hz, mono, s16p, 24 kb/s
File '20170817.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (mp3 (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 # 0x7fbe83003000] using SAR=1/1
[libx264 # 0x7fbe83003000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 # 0x7fbe83003000] profile High, level 3.1
[libx264 # 0x7fbe83003000] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '20170817.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 16000 Hz, mono, fltp, 69 kb/s
Metadata:
encoder : Lavc57.89.100 aac
frame= 7 fps=4.2 q=-1.0 Lsize= 3349kB time=00:05:27.04 bitrate= 83.9kbits/s speed= 196x
video:465kB audio:2863kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.644585%
[libx264 # 0x7fbe83003000] frame I:1 Avg QP: 7.93 size:159157
[libx264 # 0x7fbe83003000] frame P:2 Avg QP:17.16 size: 61998
[libx264 # 0x7fbe83003000] frame B:4 Avg QP:18.34 size: 48049
[libx264 # 0x7fbe83003000] consecutive B-frames: 14.3% 28.6% 0.0% 57.1%
[libx264 # 0x7fbe83003000] mb I I16..4: 48.6% 21.6% 29.8%
[libx264 # 0x7fbe83003000] mb P I16..4: 4.4% 9.8% 19.7% P16..4: 11.6% 3.0% 2.6% 0.0% 0.0% skip:48.9%
[libx264 # 0x7fbe83003000] mb B I16..4: 0.4% 0.5% 13.2% B16..8: 14.9% 3.9% 2.6% direct: 1.1% skip:63.4% L0:45.0% L1:52.1% BI: 3.0%
[libx264 # 0x7fbe83003000] 8x8 transform intra:19.2% inter:38.3%
[libx264 # 0x7fbe83003000] coded y,uvDC,uvAC intra: 52.3% 63.3% 62.4% inter: 8.6% 7.7% 6.9%
[libx264 # 0x7fbe83003000] i16 v,h,dc,p: 88% 9% 3% 0%
[libx264 # 0x7fbe83003000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 12% 45% 2% 2% 3% 2% 3% 4%
[libx264 # 0x7fbe83003000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 26% 18% 5% 5% 5% 5% 6% 6%
[libx264 # 0x7fbe83003000] i8c dc,h,v,p: 55% 18% 20% 8%
[libx264 # 0x7fbe83003000] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 # 0x7fbe83003000] ref P L0: 93.3% 0.3% 3.7% 2.8%
[libx264 # 0x7fbe83003000] ref B L0: 85.2% 14.8%
[libx264 # 0x7fbe83003000] ref B L1: 87.8% 12.2%
[libx264 # 0x7fbe83003000] kb/s:11.52
[aac # 0x7fbe83004800] Qavg: 1971.172
The problem is that the mp4 has 00:06:45 duration, and the music finished at 00:05:28
How do I chop the last silent bit off?
I tried the following:
ffmpeg -ss 0 -i 20170817.mp4 -to 00:05:28 -c copy cut.mp4
Which is worse. Adds blank silent video at front, and chop the video at middle which yet to finish.
Please note the first 5 images are correct at right music positions, only last image duration error
After running into the same extra silence at the end, it seems that explicitly limiting the video length using an output option (-to or -t) does the job. (You can use ss, -to, and -t as input or output options).
I had a similar setup to your question, albeit I took a 10-second slice of an audio file and used the concat filter to overlay it with 4 images.
# files.ffconcat
file 'image1.png'
duration 1
file 'image2.png'
duration 4
file 'image3.png'
duration 3
file 'image4.png'
duration 2
ffmpeg \
-t 10 \
-i song.mp3 \
-i files.ffconcat \
-pix_fmt yuv420p \
video.mp4
Though 1 + 4 + 3 + 2 = 10 seconds, the final video had a length of 10.84s with silence at the end, as you have observed:
frame= 274 fps= 17 q=-1.0 Lsize= 1013kB time=00:00:10.84 bitrate= 765.2kbits/s dup=343 drop=0 speed=0.683x
However, adding -t 10 as an output option
ffmpeg \
-t 10 \
-i song.mp3 \
-i files.ffconcat \
-pix_fmt yuv420p \
-t 10 \
video.mp4
results in a video which is exactly 10 seconds:
frame= 250 fps= 31 q=-1.0 Lsize= 1002kB time=00:00:10.00 bitrate= 820.0kbits/s dup=343 drop=0 speed=1.25x
Strange Aside
Interestingly enough, if the time durations for each image are 2.5 seconds, the final video does not need this workaround to be exactly 10 seconds:
# files.ffconcat
file 'image1.png'
duration 2.5
file 'image2.png'
duration 2.5
file 'image3.png'
duration 2.5
file 'image4.png'
duration 2.5
ffmpeg \
-t 10 \
-i song.mp3 \
-i files.ffconcat \
-pix_fmt yuv420p \
-t 10 \
video.mp4
frame= 250 fps= 30 q=-1.0 Lsize= 1000kB time=00:00:10.00 bitrate= 818.4kbits/s dup=307 drop=0 speed= 1.2x
This is something I was not able to figure out. But for anyone curious, here's the ffmpeg -version:
ffmpeg version 4.0.1-tessus Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100

FFMPEG RGB Lossless conversion video

I have been experiencing difficulty in finding many answers with FFMPEG documentation, forums and here.
What I am trying to do is a compress a screen capture video but with just RGB data.
The steps I am currently taking are;
ffmpeg -f avfoundation -pix_fmt 0rgb -r "30" -i "1" -vcodec libx264rgb -pix_fmt rgb24 -crf 0 -t 25 -q 0 -y ~/Desktop/RGB.mkv
south-58-45:~ danielcarter$ ffmpeg -f avfoundation -pix_fmt 0rgb -r "30" -i "1" -vcodec libx264rgb -pix_fmt rgb24 -crf 0 -t 170 -q 0 -y -v info ~/Desktop/output.mkv
ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.41)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
[avfoundation # 0x7fc39d004c00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, avfoundation, from '1':
Duration: N/A, start: 175270.249500, bitrate: N/A
Stream #0:0: Video: rawvideo ([0]RGB / 0x42475200), 0rgb, 1440x900, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264rgb))
Press [q] to stop, [?] for help
[libx264rgb # 0x7fc39d13ea00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264rgb # 0x7fc39d13ea00] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264rgb # 0x7fc39d13ea00] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=0 mixed_ref=1 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to '/Users/danielcarter/Desktop/output.mkv':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264rgb) (H264 / 0x34363248), rgb24, 1440x900, q=-1--1, 30 fps, 1k tbn, 30 tbc
Metadata:
encoder : Lavc57.89.100 libx264rgb
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 5100 fps= 30 q=-1.0 Lsize= 12167kB time=00:02:49.96 bitrate= 586.4kbits/s speed=0.999x
video:12134kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.267659%
[libx264rgb # 0x7fc39d13ea00] frame I:21 Avg QP: 0.00 size:430796
[libx264rgb # 0x7fc39d13ea00] frame P:5079 Avg QP: 0.00 size: 665
[libx264rgb # 0x7fc39d13ea00] mb I I16..4: 61.3% 0.0% 38.7%
[libx264rgb # 0x7fc39d13ea00] mb P I16..4: 0.1% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:99.9%
[libx264rgb # 0x7fc39d13ea00] 8x8 transform intra:0.0% inter:11.2%
[libx264rgb # 0x7fc39d13ea00] coded y,u,v intra: 48.0% 31.6% 29.0% inter: 0.0% 0.0% 0.0%
[libx264rgb # 0x7fc39d13ea00] i16 v,h,dc,p: 76% 22% 2% 0%
[libx264rgb # 0x7fc39d13ea00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 46% 35% 7% 2% 2% 1% 1% 1% 3%
[libx264rgb # 0x7fc39d13ea00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264rgb # 0x7fc39d13ea00] ref P L0: 83.1% 6.4% 5.3% 5.2%
[libx264rgb # 0x7fc39d13ea00] kb/s:584.71
This captures the screen on my mac. To the best of my knowledge, this creates a lossless file and I have compared screen shots that confirm this.
The next step is where I think I have an issue.
Because I want to run the compression on raw RGB data I need to convert the MKV to an RGB file;
ffmpeg -i ~/Desktop/RGB.mkv -c:v rawvideo -pix_fmt rgb24 -crf 0 -ss 00:00:03 -to 00:02:01 -q 0 -y ~/Desktop/out.rgb
south-58-45:~ danielcarter$ ffmpeg -i ~/Desktop/output.mkv -c:v rawvideo -pix_fmt rgb24 -crf 0 -ss 00:00:03 -to 00:02:01 -q 0 -y ~/Desktop/out.rgb
ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.41)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, matroska,webm, from '/Users/danielcarter/Desktop/output.mkv':
Metadata:
ENCODER : Lavf57.71.100
Duration: 00:02:50.00, start: 0.000000, bitrate: 586 kb/s
Stream #0:0: Video: h264 (High 4:4:4 Predictive), gbrp(tv, gbr/unknown/unknown, progressive), 1440x900, 30 fps, 30 tbr, 1k tbn, 60 tbc (default)
Metadata:
ENCODER : Lavc57.89.100 libx264rgb
DURATION : 00:02:50.000000000
Codec AVOption crf (Select the quality for constant quality mode) specified for output file #0 (/Users/danielcarter/Desktop/out.rgb) 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 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, rawvideo, to '/Users/danielcarter/Desktop/out.rgb':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1440x900, q=2-31, 933120 kb/s, 30 fps, 30 tbn, 30 tbc (default)
Metadata:
DURATION : 00:02:50.000000000
encoder : Lavc57.89.100 rawvideo
frame= 3540 fps=111 q=-0.0 Lsize=13440938kB time=00:01:58.00 bitrate=933120.0kbits/s speed=3.68x
video:13440938kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
Once I have this I can then compress and decompress successfully. I then get a working file to play back using;
ffmpeg -f rawvideo -vcodec rawvideo -s 1440x900 -r 30 -pix_fmt rgb24 -i ~/Desktop/out.rgb -c:v libx264rgb -pix_fmt rgb24 -x264opts keyint=300:min-keyint=300:no-scenecut -y -crf 0 ~/Desktop/rgbplay.mkv
south-58-45:~ danielcarter$ ffmpeg -f rawvideo -vcodec rawvideo -s 1440x900 -r 30 -pix_fmt rgb24 -i ~/Desktop/out.rgb -c:v libx264rgb -pix_fmt rgb24 -x264opts keyint=300:min-keyint=300:no-scenecut -y -crf 0 ~/Desktop/rgbplay.mkv
ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.41)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
[rawvideo # 0x7fb1f9002600] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from '/Users/danielcarter/Desktop/out.rgb':
Duration: 00:01:58.00, start: 0.000000, bitrate: 933120 kb/s
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1440x900, 933120 kb/s, 30 tbr, 30 tbn, 30 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264rgb))
Press [q] to stop, [?] for help
[libx264rgb # 0x7fb1f9010c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264rgb # 0x7fb1f9010c00] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264rgb # 0x7fb1f9010c00] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=0 mixed_ref=1 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=300 keyint_min=151 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to '/Users/danielcarter/Desktop/rgbplay.mkv':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264rgb) (H264 / 0x34363248), rgb24, 1440x900, q=-1--1, 30 fps, 1k tbn, 30 tbc
Metadata:
encoder : Lavc57.89.100 libx264rgb
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 3540 fps= 64 q=-1.0 Lsize= 8319kB time=00:01:57.96 bitrate= 577.7kbits/s speed=2.13x
video:8297kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.273154%
[libx264rgb # 0x7fb1f9010c00] frame I:12 Avg QP: 0.00 size:437670
[libx264rgb # 0x7fb1f9010c00] frame P:3528 Avg QP: 0.00 size: 919
[libx264rgb # 0x7fb1f9010c00] mb I I16..4: 61.9% 0.0% 38.1%
[libx264rgb # 0x7fb1f9010c00] mb P I16..4: 0.1% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:99.8%
[libx264rgb # 0x7fb1f9010c00] 8x8 transform intra:0.0% inter:15.1%
[libx264rgb # 0x7fb1f9010c00] coded y,u,v intra: 49.7% 36.5% 33.7% inter: 0.0% 0.0% 0.0%
[libx264rgb # 0x7fb1f9010c00] i16 v,h,dc,p: 73% 25% 1% 0%
[libx264rgb # 0x7fb1f9010c00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 45% 36% 7% 2% 2% 2% 2% 1% 3%
[libx264rgb # 0x7fb1f9010c00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264rgb # 0x7fb1f9010c00] ref P L0: 81.3% 7.7% 6.7% 4.3%
[libx264rgb # 0x7fb1f9010c00] kb/s:575.96
But here I have pixel variance. My guess is there is a RGB-YUV-RGB conversion happening somewhere but I am not smart enough to work out where.
If any of you can help I would forever grateful.
Here is a picture of the two stills side by side that shows the differences;
pixel difference
If you need anything more I can post it also.
Cheers,
DC
I managed to get this to work by removing a step.
The conversion from mkv->rgb was producing the problem, it was using gbrp as the pixel format and this created slight differences in colour across the whole screen. Thank you to Mulvya for pointing out the range markers too, without that I would not have known where to look.
To get this to work I use the following code to screen capture direct to RGB;
ffmpeg -f avfoundation -pix_fmt 0rgb -color_range 2 -r "30" -i "1" -vcodec rawvideo -pix_fmt rgb24 -color_range 2 -t 210 -q 0 -y -v info ~/Desktop/output.rgb
Then can convert that to an MKV file for playback using;
ffmpeg -report -f rawvideo -vcodec rawvideo -s 1440x900 -r 30 -pix_fmt rgb24 -color_range 2 -i ~/Desktop/output.rgb -c:v libx264rgb -pix_fmt rgb24 -ss 00:00:04 -to 00:02:02 -color_range 2 -x264opts crf=0 -y ~/Desktop/rgbplay.mkv
Thank you for everything, I can sleep again haha

Resources