Patola
Patola

Reputation: 673

Combine two Videos with different framerates using ffmpeg

ffmpeg -f concat -i mylist.txt -c copy output.mp4

Combined video produced by above command is 17 mins. I think its because of the framerates. Is there a way to get proper output.

Is there a tool I can use to change the framerate of one vid to match the other.

Please see text below to see configurations of two videos.

ffmpeg version 4.4-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      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, mov,mp4,m4a,3gp,3g2,mj2, from 'Full.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp41isom
    creation_time   : 2021-06-01T10:57:14.000000Z
  Duration: 00:08:57.08, start: 0.000000, bitrate: 2527 kb/s
  Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 2526 kb/s, 30.30 fps, 30.30 tbr, 30k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2021-06-01T10:57:14.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:11.93, start: 0.000000, bitrate: 20939 kb/s
  Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 20973 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 2 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
File 'output.mp4' already exists. Overwrite? [y/N] y
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp41isom
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 2526 kb/s, 30.30 fps, 30.30 tbr, 30k tbn, 30k tbc (default)
    Metadata:
      creation_time   : 2021-06-01T10:57:14.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 2 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=16275 fps=0.0 q=-1.0 Lsize=  165734kB time=00:08:57.04 bitrate=2528.1kbits/s speed=3.02e+03x
video:165653kB audio:3kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.047347%

Upvotes: 0

Views: 2741

Answers (1)

llogan
llogan

Reputation: 133693

concat demuxer

You can use the concat demuxer. It will require multiple commands, but the concat demuxer can preserve the quality of the main video via stream copy mode.

But both files have to have the same attributes.

  1. Full.mp4 is longer than 1.mp4, so make 1.mp4 like Full.mp4:

    ffmpeg -i 1.mp4 -c:v libx264 -profile:v baseline -video_track_timescale 30k -c:a copy 1_new.mp4
    
  2. Full.mp4 does not have audio, but 1.mp4 does. So add silent/blank/dummy/filler audio to Full.mp4 with the anullsrc filter:

    ffmpeg -i Full.mp4 -f lavfi -i anullsrc=cl=stereo:r=48000 -c:v copy -c:a aac -shortest Full_new.mp4
    
  3. Make mylist.txt containing:

    file 'Full_new.mp4'
    file '1_new.mp4'
    
  4. Concatenate:

    ffmpeg -f concat -i mylist.txt -c copy output.mp4
    

concat filter

Or you can do everything in one command using the concat filter. This will re-encode all inputs.

See How to concatenate videos in ffmpeg with different attributes? for several examples.

Upvotes: 1

Related Questions