Synchronizing RTSP signals with FFMPEG - ffmpeg

I have achieved to merge two RTSP signals in one with FFMPEG but in the resulting stream, the first input has a delay of between 2 and 5 seconds with respect to the second. And it is always the first input that is delayed compared to the second.
The two RTSP signals come from the same camera model, same configuration, same room ...
However, if I put the same RTSP signal (either of the two) as input 1 and input 2, the same thing happens. Despite being the same signal, the first input is delayed compared to the second one.
How could I get them synchronized?
This is the command that I execute:
ffmpeg -rtsp_transport tcp -thread_queue_size 512 -rtbufsize 50M -r 15
-i rtsp://XXXX -rtsp_transport tcp -thread_queue_size 512 -rtbufsize 50M -r 15
-c:a aac -i rtsp://YYYY -filter_complex "[0:v]pad=iw*2:ih,setpts=PTS-STARTPTS[bg];
[1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w[out]" -map "[out]" -f hls
-hls_time 2 -hls_list_size 5 -use_localtime 1 -use_localtime_mkdir 1
-hls_segment_filename 'LIVE/file-%s.ts' -map a -ar 16000 -ac 1 -ab 64000 -c:a aac
-y output.m3u8
Here you have the process informationn:
ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --disable-jack --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[rtsp # 0x7fe284000e00] Missing PPS in sprop-parameter-sets, ignoring
Input #0, rtsp, from 'rtsp://XXXX':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1280x720, 15 fps, 15 tbr, 90k tbn, 30 tbc
Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp
[rtsp # 0x7fe28484de00] Missing PPS in sprop-parameter-sets, ignoring
Input #1, rtsp, from 'rtsp://XXXX':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #1:0: Video: h264 (Main), yuv420p(progressive), 1280x720, 15 fps, 15 tbr, 90k tbn, 30 tbc
Stream #1:1: Audio: aac (LC), 16000 Hz, mono, fltp
Stream mapping:
Stream #0:0 (h264) -> pad (graph 0)
Stream #1:0 (h264) -> setpts (graph 0)
overlay (graph 0) -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 # 0x7fe286802000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x7fe286802000] profile High, level 4.0
[libx264 # 0x7fe286802000] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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=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=1 b_bias=0 direct=1 weightb=1 open_gop=1 weightp=2 keyint=250 keyint_min=15 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
[hls # 0x7fe286800000] Opening 'LIVE/file-1524728763.ts' for writing
Output #0, hls, to 'output.m3u8':
Metadata:
title : Media Presentation
encoder : Lavf57.83.100
Stream #0:0: Video: h264 (libx264), yuv420p, 2560x720, q=-1--1, 15 fps, 90k tbn, 15 tbc (default)
Metadata:
encoder : Lavc57.107.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp, 64 kb/s
Metadata:
encoder : Lavc57.107.100 aac
[hls # 0x7fe286800000] Opening 'LIVE/file-1524728782.ts' for writinged=1.09x
[hls # 0x7fe286800000] Opening 'output.m3u8.tmp' for writing
[hls # 0x7fe286800000] Opening 'output.m3u8.tmp' for writing=N/A speed=1.07x
frame= 396 fps= 15 q=-1.0 Lsize=N/A time=00:00:27.00 bitrate=N/A speed=1.05x
video:2946kB audio:147kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

From the ffmpeg documentation
https://ffmpeg.org/ffmpeg-filters.html#Examples-139:
try setting video pts with
setpts='(RTCTIME - RTCSTART) / (TB * 1000000)'
(some documentation says this is deprecated but I am using the November 27th build and it works.)
Sync the video streams to the first stream i.e
-map "[out]",0:v
and set pts on the audio
-af 'asetpts=N/SR/TB'
YMMV, but it works with my cheap Chinese IP cams

Related

ffmpeg filter_complex concat never completes

I am trying to concatenate mp4 files into a single file. I am attempting to use the concat filter directly for reasons independent from this question (so -i list.txt is not a valid solution). All video files in question are between 4 and 20 minutes in length.
What I am executing:
% ffmpeg -i f01.mp4 -i f02.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4
This is my understanding of the form of this command from references such as FFmpeg Filters Documentation: concat and Concatenate Videos Together Using FFMPEG!.
What happens:
ffmpeg gives a lot of output as it checks the metadata for each stream and then begins processing. After a short duration (several seconds to a minute or so, seems to be prortional to the duration of the first video) I start seeing messages like this:
More than 1000 frames duplicated
More than 10000 frames duplicated 512kB time=00:00:00.12 bitrate=32771.0kbits/s dup=33365 drop=0 speed=0.00449x
More than 100000 frames duplicated 1280kB time=00:00:00.17 bitrate=61442.1kbits/s dup=66730 drop=0 speed=0.00272x
... and then the process never completes. If I leave my computer running for 24 hours, ffmpeg is still using max available CPU (200-300%). The output file is 48 bytes in length.
Note: the inputs are only a few minutes each, so individually re-encoding the inputs would take only a few minutes each.
Note: if I change the command to use f01.mp4 for both source 0 and source 1, the command completes as expected in under 5 minutes:
% # example that works:
% # note, however, that this just repeats the same source twice
% ffmpeg -i f01.mp4 -i f01.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4
Full output:
Here is the complete output of a run in case it's helpful:
% ffmpeg -i f01.mp4 -i f02.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.mp4
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.3 (clang-1103.0.32.62)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
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
libavresample 4. 0. 0 / 4. 0. 0
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 'f01.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2020-06-04T21:34:26.000000Z
encoder : HandBrake 1.3.2 2020050300
Duration: 00:04:14.66, start: 0.000000, bitrate: 525 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 708x478 [SAR 8:9 DAR 944:717], 366 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2020-06-04T21:34:26.000000Z
handler_name : VideoHandler
Stream #0:1(jpn): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 149 kb/s (default)
Metadata:
creation_time : 2020-06-04T21:34:26.000000Z
handler_name : Stereo
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'f02.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2020-06-04T21:38:15.000000Z
encoder : HandBrake 1.3.2 2020050300
Duration: 00:06:30.95, start: 0.000000, bitrate: 1328 kb/s
Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 708x478 [SAR 8:9 DAR 944:717], 1179 kb/s, 29.97 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2020-06-04T21:38:15.000000Z
handler_name : VideoHandler
Stream #1:1(jpn): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 140 kb/s (default)
Metadata:
creation_time : 2020-06-04T21:38:15.000000Z
handler_name : Stereo
File 'output.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 (h264) -> concat:in0:v0
Stream #0:1 (aac) -> concat:in0:a0
Stream #1:0 (h264) -> concat:in1:v0
Stream #1:1 (aac) -> concat:in1:a0
concat:out:v0 -> Stream #0:0 (libx264)
concat:out:a0 -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[mp4 # 0x7ff130014000] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
[libx264 # 0x7ff130021200] using SAR=8/9
[libx264 # 0x7ff130021200] MB rate (1350000000) > level limit (16711680)
[libx264 # 0x7ff130021200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x7ff130021200] profile High, level 6.2, 4:2:0, 8-bit
[libx264 # 0x7ff130021200] 264 - core 160 r3011 cde9a93 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - 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 'output.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 708x478 [SAR 8:9 DAR 944:717], q=-1--1, 1000k tbn, 1000k tbc (default)
Metadata:
encoder : Lavc58.91.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
encoder : Lavc58.91.100 aac
More than 1000 frames duplicated
More than 10000 frames duplicated 512kB time=00:00:00.12 bitrate=32771.0kbits/s dup=33365 drop=0 speed=0.00449x
More than 100000 frames duplicated 1280kB time=00:00:00.17 bitrate=61442.1kbits/s dup=66730 drop=0 speed=0.00272x
frame=667333 fps=1079 q=33.0 size= 14848kB time=00:00:00.76 bitrate=158379.2kbits/s dup=667312 drop=0 speed=0.00124x
As the warning in the log says, Frame rate very high for a muxer not efficiently supporting it. This happens because concat unsets the stream frame rate, which happens when the tbr of all video streams don't match. ffmpeg will then use the time_base as the effective frame rate and then duplicate frames to match that frame rate. In this case, it's 90000, so this effectively explodes resource use and slows down the process.
Add -vsync 2 to avoid frame duplication.
ffmpeg -i f01.mp4 -i f02.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" -vsync 2 -map "[v]" -map "[a]" output.mp4

FFMPEG failing to convert mov to flv

FFMPEG issue that I am not familiar with. seems to only happen with this particular file. Anyone by any chance can take a look at this long out put and provide any feedback on what might actually be causing this?
ffmpeg_18.exe -i "E:\TESTFILES\115637.mov" -vcodec libx264 -b:v 700k -s 720x480 -r 29.97 -pix_fmt yuv420p -vf yadif -aspect 4:3 -acodec libvo_aacenc -b:a 96k -ar 44100 -f mp4 -y "E:\TESTFILES\test\115637.flv"
ffmpeg version N-39877-g4fa706a Copyright (c) 2000-2012 the FFmpeg developers
built on Apr 16 2012 14:53:47 with gcc 4.6.3
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-li
bnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 51. 46.100 / 51. 46.100
libavcodec 54. 14.101 / 54. 14.101
libavformat 54. 3.100 / 54. 3.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 70.100 / 2. 70.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 11.100 / 0. 11.100
libpostproc 52. 0.100 / 52. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'E:\TESTFILES\115637.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2018-05-03 20:48:28
Duration: 00:00:30.03, start: 0.000000, bitrate: 154663 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 151585 kb/s, SAR 1920:1920 DAR 16:9, 29.97 fps, 29.97 tbr, 30k tbn, 60k tbc
Metadata:
creation_time : 2018-05-03 20:48:28
handler_name : Apple Alias Data Handler
Stream #0:1(eng): Audio: pcm_s16le (lpcm / 0x6D63706C), 48000 Hz, 4 channels, s16, 3072 kb/s
Metadata:
creation_time : 2018-05-03 20:48:28
handler_name : Apple Alias Data Handler
Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 2018-05-03 20:51:29
handler_name : Apple Alias Data Handler
timecode : 00:00:00;00
[buffer # 035c33a0] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1920/1920 sws_param:flags=2
[yadif # 01e7caa0] mode:0 parity:-1 auto_enable:0
[scale # 01e7c6a0] w:1920 h:1080 fmt:yuv420p sar:1920/1920 -> w:720 h:480 fmt:yuv420p sar:32/27 flags:0x4
[libx264 # 035b8c40] using SAR=8/9
[libx264 # 035b8c40] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX FMA3
[libx264 # 035b8c40] profile High, level 3.0
[libx264 # 035b8c40] 264 - core 120 r2164 da19765 - 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=24 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=abr mbtree=1 bitra
te=700 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[libvo_aacenc # 01e7bae0] Unable to set encoding parameters
Output #0, mp4, to 'E:\TESTFILES\test\115637.flv':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2018-05-03 20:48:28
Stream #0:0(eng): Video: h264, yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=-1--1, 700 kb/s, 90k tbn, 29.97 tbc
Metadata:
creation_time : 2018-05-03 20:48:28
handler_name : Apple Alias Data Handler
Stream #0:1(eng): Audio: aac, 44100 Hz, 4 channels, s16, 96 kb/s
Metadata:
creation_time : 2018-05-03 20:48:28
handler_name : Apple Alias Data Handler
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (pcm_s16le -> libvo_aacenc)
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
Your ffmpeg is really old
You can get a recent version for Windows at Zeranoe.
libvo_aacenc is crappy
It was removed from ffmpeg years ago. Quality was bad and it could not handle more than 2 channels. Update and use the built-in AAC encoder instead:
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset medium -vf "yadif,scale=-2:720,format=yuv420p" -c:a aac -ac 2 -b:a 96k output.flv
This example downmixes your 4 channel input to 2 channels (stereo) with the -ac 2 option.
See FFmpeg Wiki: H.264 for video encoding info.

FFmpeg stuck on frame 0 during time-lapse conversion with `-ss` start time

I have a long video that I'd like to speed up into a time-lapse. Following the FFmpeg wiki, I came up with this incantation:
ffmpeg -i IMG_0238.MOV -r 60 -ss 00:04:41 -filter:v "setpts=PTS/60.0" -an output.mp4
It should clip off the first few minutes, then create a new 60fps video file at 60x the speed.
Although it spins all my CPU cores up to 100%, the status bar simply shows frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x and never progresses.
The problem seems related to the -ss 00:04:41 flag, which specifies the start time; I want to drop the first 4 minutes 41 seconds of source video. When I omit this option, the video conversion succeeds.
Full log follows.
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.30)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[mov,mp4,m4a,3gp,3g2,mj2 # 0x7fb59b800000] stream 2, missing mandatory atoms, broken header
[mov,mp4,m4a,3gp,3g2,mj2 # 0x7fb59b800000] stream 3, missing mandatory atoms, broken header
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'IMG_0238.MOV':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2017-04-20T16:25:14.000000Z
com.apple.quicktime.location.ISO6709: +36.4610+025.3727+123.613/
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 7
com.apple.quicktime.software: 10.3.1
com.apple.quicktime.creationdate: 2017-04-20T19:25:13+0300
Duration: 01:22:45.53, start: -0.000023, bitrate: 44171 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 3840x2160, 44077 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc (default)
Metadata:
rotate : 180
creation_time : 2017-04-20T16:25:14.000000Z
handler_name : Core Media Data Handler
encoder : H.264
Side data:
displaymatrix: rotation of -180.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 84 kb/s (default)
Metadata:
creation_time : 2017-04-20T16:25:14.000000Z
handler_name : Core Media Data Handler
Stream #0:2(und): Data: none (mebx / 0x7862656D) (default)
Metadata:
creation_time : 2017-04-20T16:25:14.000000Z
handler_name : Core Media Data Handler
Stream #0:3(und): Data: none (mebx / 0x7862656D) (default)
Metadata:
creation_time : 2017-04-20T16:25:14.000000Z
handler_name : Core Media Data Handler
File 'output.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 # 0x7fb59b82b800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 # 0x7fb59b82b800] profile High, level 5.2
[libx264 # 0x7fb59b82b800] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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 'output.mp4':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
com.apple.quicktime.creationdate: 2017-04-20T19:25:13+0300
com.apple.quicktime.location.ISO6709: +36.4610+025.3727+123.613/
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 7
com.apple.quicktime.software: 10.3.1
encoder : Lavf57.83.100
Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 3840x2160, q=-1--1, 60 fps, 15360 tbn, 60 tbc (default)
Metadata:
encoder : Lavc57.107.100 libx264
creation_time : 2017-04-20T16:25:14.000000Z
handler_name : Core Media Data Handler
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
displaymatrix: rotation of -0.00 degrees
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
Specify the -ss parameter before the -i parameter:
ffmpeg -ss 00:04:41 -i IMG_0238.MOV -r 60 -filter:v "setpts=PTS/60.0" -an output.mp4
What -ss as an output option does, is discard output till frames with the specified inpoint are received. Since that can take some time, the progress counter will appear to be 'stuck' but processing is ongoing. In your case, what further compounds the issue is that since you're collapsing timestamps to 1/60th, ss of 04:41 represents 04:41 x 60 of input being discarded. Increases the progress delay a lot, but more importantly, your output doesn't start where you want it to.
By using -ss as input option, ffmpeg will discard 04:41 of the input and then process the rest. The progress counter will also be active immediately.

FFMPEG error while converting flv1 (flv) -> h264 (libx264)

I am trying to covert flv format video to h264 codec with mp4 format video, but am facing the following error:
Command I executed:
ffmpeg -i input_video.flv -c:v libx264 output.mp4
Error:
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
Logs:
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --enable-opencl --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, flv, from 'input.flv':
Metadata:
encoder : Lavf53.24.2
Duration: 00:00:53.32, start: 0.000000, bitrate: 787 kb/s
Stream #0:0: Video: flv1, yuv420p, 320x240, 500 kb/s, 25 fps, 25 tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: aac (LC), 48000 Hz, 5.1, fltp, 384 kb/s
[libx264 # 0x7ff885000c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 # 0x7ff885000c00] profile High, level 1.3
[libx264 # 0x7ff885000c00] 264 - core 144 r2533 c8a773e - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - 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
[libvo_aacenc # 0x7ff885001e00] Unable to set encoding parameters
Output #0, mp4, to 'output1.mp4':
Metadata:
encoder : Lavf53.24.2
Stream #0:0: Video: h264 (libx264), yuv420p, 320x240, q=-1--1, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc56.41.100 libx264
Stream #0:1: Audio: aac, 0 channels, 128 kb/s
Metadata:
encoder : Lavc56.41.100 libvo_aacenc
Stream mapping:
Stream #0:0 -> #0:0 (flv1 (flv) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (libvo_aacenc))
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
What could be the reason for this ?
Update: Based on the console output now included in the Q, the error has nothing to do with the video, but I'll leave my earlier answer below in case anyone finding this question does get the same error from the video encoder.
The error is being reported by the 3rd party AAC encoder, which is now obsolete, and only supports two channels.
There are three ways to tackle this:
#1 Copy audio stream over
ffmpeg -i input.flv -c:a copy output.mp4
#2 Upgrade to recent FFmpeg and run original command in the question
#3 Re-encode using current binary and old encoder (least recommended)
ffmpeg -i input.flv -ac 2 -b:a 128k -strict -2 output.mp4
Older answer:
Most common reason for this error is that the dimensions aren't a multiple of two, and FFmpeg is outputting using pixel encoding YUV420P which requires them to be.
Try
ffmpeg -i input.flv -vf "scale=2*trunc(iw/2):-2" output.mp4
The scale filter makes both the dimensions even.

ffmpeg: Too many bits per frame requested [duplicate]

This question already has answers here:
ffmpeg Too many bits per frame requested
(2 answers)
Closed 6 years ago.
Sometimes there is an issue when i try to convert to mp4 using ffmpeg. I'm getting issue Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height.
This is the command:
ffmpeg -y -i input.mp4 -i watermark.png -filter_complex 'scale=-2:360,overlay=(main_w-overlay_w)-20:(main_h-overlay_h)-20' -codec:v libx264 -profile:v main -preset slow -b:v 300k -maxrate 300k -bufsize 600k -threads 0 -codec:a aac -strict experimental -b:a 128k -crf 20 output.mp4 1> output.log 2>&1
Here the error log:
ffmpeg version 2.4.3 Copyright (c) 2000-2014 the FFmpeg developers
built on Nov 16 2014 22:36:57 with gcc 4.8.2 (GCC)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/man --docdir=/usr/doc/ffmpeg-2.4.3 --enable-gpl --enable-version3 --enable-avfilter --enable-avresample --enable-libass --enable-libdc1394 --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libzvbi --enable-postproc --enable-runtime-cpudetect --enable-vaapi --enable-vdpau --enable-memalign-hack --enable-pthreads --enable-x11grab --enable-bzlib --enable-zlib --enable-shared --enable-static --disable-debug --arch=x86_64 --enable-pic --extra-cflags='-I/tmp/build/tmp-ffmpeg/ffmpegdeps/usr/include -DRUNTIME_CPUDETECT' --extra-ldflags='-L/tmp/build/tmp-ffmpeg/ffmpegdeps/usr/lib64 -ldl -lssl -lcrypto -lz -lusb' --pkg-config-flags=--static
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.15.102
Duration: 00:00:06.76, start: 0.000000, bitrate: 1856 kb/s
Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 720x480, 1804 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 54 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, png_pipe, from 'watermark.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba, 120x35, 25 tbr, 25 tbn, 25 tbc
[libx264 # 0x2179d80] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle
[libx264 # 0x2179d80] profile Main, level 3.0
[libx264 # 0x2179d80] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x1:0x111 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 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=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=crf mbtree=1 crf=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=300 vbv_bufsize=600 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
[aac # 0x217ba40] Too many bits per frame requested
Output #0, mp4, to 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.15.102
Stream #0:0: Video: h264 (libx264), yuv420p, 540x360, q=-1--1, 300 kb/s, 30 fps, 30 tbn, 30 tbc (default)
Metadata:
encoder : Lavc56.1.100 libx264
Stream #0:1(eng): Audio: aac, 0 channels, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc56.1.100 aac
Stream mapping:
Stream #0:0 (h264) -> scale (graph 0)
Stream #1:0 (png) -> overlay:overlay (graph 0)
overlay (graph 0) -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
The relevant messages:
[aac # 0x217ba40] Too many bits per frame requested
[…]
Error while opening encoder for output stream #0:1
This is from the native FFmpeg AAC encoder named "aac". Your options:
Stream copy the input AAC audio instead of re-encoding (-c:a copy).
Use a different AAC encoder. This would require re-compiling ffmpeg because your build appears to only support the native FFmpeg AAC encoder.
Use a lower audio bitrate (-b:a).
Use a higher audio rate (-ar).
Other notes
-b:v and -crf are mutually exclusive: you should choose only one. In you case -b:v was ignored.
-threads 0 is the default for this encoder, meaning that x264 will automatically select the appropriate number of threads, so you can remove this option.
The H.264 profile (-profile:v) only needs to be set if your target players or devices do not support whatever profile the encoder automatically selects.
FFmpeg 2.4.3 is considered old. General users are recommended to use ffmpeg from current git master if possible (meaning use a build from the most recent code). Downloading a static build is an easy way to do that.
Stack Overflow is for programming questions only. If you have additional ffmpeg cli usage questions they should be asked at Super User.
There seems to be a problem with your AAC audio stream #0:1. It shows 0 channels in the console output.
Try adding -analyzeduration and -probesize to your command to increase the analysis time and see if it detects them or drop the audio stream entirely / check the source file integrity.
probesize integer (input)
Set probing size in bytes, i.e. the size of
the data to analyze to get stream information. A higher value will
enable detecting more information in case it is dispersed into the
stream, but will increase latency. Must be an integer not lesser than
32. It is 5000000 by default.
analyzeduration integer (input)
Specify how many microseconds are
analyzed to probe the input. A higher value will enable detecting more
accurate information, but will increase latency. It defaults to
5,000,000 microseconds = 5 seconds.

Resources