Wednesday, September 26, 2018

ffmpeg options

some mobile devices cannot decode high resolution video or higher level H264 video.
ffmpeg can be used to re-encode these videos.

here's are some examples.

c:\portable\ffmpeg\bin\ffmpeg -i input.mp4 -vcodec libx264 -crf 23 -preset fast -profile:v baseline -level 3 -refs 6 -vf "scale=640:-1, pad=iw:480:0:(oh-ih)/2, format=yuv420p" -acodec copy output.mp4


c:\portable\ffmpeg\bin\ffmpeg -i "input.mp4" -vcodec libx264 -crf 23 -preset fast -profile:v baseline -level 3 -refs 6 -vf "format=yuv420p" -acodec copy "output.mp4"




And also

To increase the volume of the first audio track for 10dB use:
ffmpeg -i inputfile -vcodec copy -af "volume=10dB" outputfile
To decrease the volume of the first audio track for 5dB use:
ffmpeg -i inputfile -vcodec copy -af "volume=-5dB" outputfile


to concatenate multiple files ito one file (in case for making single file from separate mutiple balckbox files which have multiple video stream (fron and rear video))

Create a file mylist.txt as below

  # this is a comment

  file '/path/to/file1.avi'
  file '/path/to/file2.avi'
  file '/path/to/file3.avi'
 
then use this command
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.avi
this command makes single out.avi file which have two video stream and a audio stream.
To make single video stream concatenancted file, use concat protocol method.
ffmpeg -i "concat:REC1.avi|REC2.avi|REC3.avi" - c copy d:\_download\out.avi 
but this command failed with message  "[NULL @ 000002070a009d00] Unable to find a suitable output format for 'pipe:'
pipe:: Invalid argument"
ffmpeg -i "concat:REC1.avi|REC2.avi|REC3.avi" d:\_download\out.avi works for me.
 
to choose certain video stream, use filter_complex below.
g:\DRIVING>ffmpeg -i REC1.avi -i REC2.avi -filter_complex "[0:v:1][0:a:0][1:v:1][1:a:0]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" d:\_download\out1.mp4
ffmpeg version 2021-05-02-git-5541cffa17-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 0.100 / 59. 0.100
libavformat 59. 0.100 / 59. 0.100
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.101 / 8. 0.101
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
[h264 @ 000001bc05d2f4c0] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d2f4c0] decode_slice_header error
[h264 @ 000001bc05d2f4c0] no frame!
[h264 @ 000001bc05d2f4c0] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d2f4c0] decode_slice_header error
[h264 @ 000001bc05d2f4c0] no frame!
[h264 @ 000001bc05d2f4c0] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d2f4c0] decode_slice_header error
[h264 @ 000001bc05d2f4c0] no frame!
[h264 @ 000001bc05d2f4c0] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d2f4c0] decode_slice_header error
[h264 @ 000001bc05d2f4c0] no frame!
Guessed Channel Layout for Input Stream #0.2 : mono
Input #0, avi, from 'REC1.avi':
Duration: 00:01:00.13, start: 0.000000, bitrate: 13950 kb/s
Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1280x720, 30 fps, 30 tbr, 30 tbn
Stream #0:1: Video: h264 (Main) (H264 / 0x34363248), yuv420p(progressive), 1280x720, 30 fps, 30 tbr, 30 tbn
Stream #0:2: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, mono, s16, 352 kb/s
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
[h264 @ 000001bc05d3f180] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 000001bc05d3f180] decode_slice_header error
[h264 @ 000001bc05d3f180] no frame!
Guessed Channel Layout for Input Stream #1.2 : mono
Input #1, avi, from 'REC2.avi':
Duration: 00:01:00.13, start: 0.000000, bitrate: 13950 kb/s
Stream #1:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1280x720, 30 fps, 30 tbr, 30 tbn
Stream #1:1: Video: h264 (Main) (H264 / 0x34363248), yuv420p(progressive), 1280x720, 30 fps, 30 tbr, 30 tbn
Stream #1:2: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, mono, s16, 352 kb/s
Stream mapping:
Stream #0:1 (h264) -> concat:in0:v0
Stream #0:2 (pcm_s16le) -> concat:in0:a0
Stream #1:1 (h264) -> concat:in1:v0
Stream #1:2 (pcm_s16le) -> concat:in1:a0
concat:out:v0 -> Stream #0:0 (libx264)
concat:out:a0 -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 000001bc06548040] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001bc06548040] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 000001bc06548040] 264 - core 161 r3053 c347e7a - 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=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=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 'd:\_download\out1.mp4':
Metadata:
encoder : Lavf59.0.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 1280x720, q=2-31, 30 fps, 15360 tbn (default)
Metadata:
encoder : Lavc59.0.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), 22050 Hz, mono, fltp, 69 kb/s (default)
Metadata:
encoder : Lavc59.0.100 aac
frame= 3608 fps= 64 q=-1.0 Lsize= 82162kB time=00:02:00.27 bitrate=5596.1kbits/s dup=11 drop=0 speed=2.13x
video:81343kB audio:721kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.119143%
[libx264 @ 000001bc06548040] frame I:28 Avg QP:24.31 size: 75653
[libx264 @ 000001bc06548040] frame P:1173 Avg QP:25.77 size: 30988
[libx264 @ 000001bc06548040] frame B:2407 Avg QP:27.43 size: 18623
[libx264 @ 000001bc06548040] consecutive B-frames: 10.4% 0.7% 3.9% 85.0%
[libx264 @ 000001bc06548040] mb I I16..4: 17.5% 28.9% 53.6%
[libx264 @ 000001bc06548040] mb P I16..4: 6.1% 15.0% 6.2% P16..4: 40.6% 14.3% 5.1% 0.0% 0.0% skip:12.7%
[libx264 @ 000001bc06548040] mb B I16..4: 1.9% 1.9% 1.5% B16..8: 51.9% 11.7% 2.0% direct:12.0% skip:17.2% L0:55.3% L1:39.3% BI: 5.4%
[libx264 @ 000001bc06548040] 8x8 transform intra:48.7% inter:33.7%
[libx264 @ 000001bc06548040] coded y,uvDC,uvAC intra: 82.0% 27.7% 3.2% inter: 33.7% 13.0% 0.4%
[libx264 @ 000001bc06548040] i16 v,h,dc,p: 10% 20% 41% 29%
[libx264 @ 000001bc06548040] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 17% 28% 6% 7% 5% 10% 5% 10%
[libx264 @ 000001bc06548040] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 25% 24% 6% 7% 5% 9% 4% 7%
[libx264 @ 000001bc06548040] i8c dc,h,v,p: 66% 19% 13% 3%
[libx264 @ 000001bc06548040] Weighted P-Frames: Y:2.5% UV:0.7%
[libx264 @ 000001bc06548040] ref P L0: 58.6% 13.2% 17.5% 10.6% 0.2%
[libx264 @ 000001bc06548040] ref B L0: 88.0% 8.7% 3.3%
[libx264 @ 000001bc06548040] ref B L1: 94.1% 5.9%
[libx264 @ 000001bc06548040] kb/s:5540.63
[aac @ 000001bc0633c480] Qavg: 64920.262