Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ffmpeg - Concatenating two.mov files results in identical sized file

I try to concatenate two video files a.mov & b.mov on Win 10 using ffmpeg with the following command:

ffmpeg -safe 0 -f concat -i list.txt -vcodec copy -acodec copy c.mov

There are no errors displayed however when I open the resulting file c it has the same length as file a with the last frame appering to be a frame of b. File a is a longer video, file b are credits (couple of seconds) made with ffmpeg from an image file. Both files have the same aspect ratio, size and framerate.

I try to concatenate two video files a.mov & b.mov on Win 10 using ffmpeg with the following command:

ffmpeg -safe 0 -f concat -i list.txt -vcodec copy -acodec copy c.mov

There are no errors displayed however when I open the resulting file c it has the same length as file a with the last frame appering to be a frame of b. File a is a longer video, file b are credits (couple of seconds) made with ffmpeg from an image file. Both files have the same aspect ratio, size and framerate.

Here the log:

  ffmpeg -n -i a.mov -i b.mov 
    ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers   built with gcc 9.3.1 (GCC) 20200523  configuration: --enable-gpl --enable-version3 --enable-sdl2
    --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt   libavutil      56. 31.100 / 56. 31.100   libavcodec     58. 54.100 /
    58. 54.100   libavformat    58. 29.100 / 58. 29.100   libavdevice    58.  8.100 / 58.  8.100   libavfilter     7. 57.100 /  7. 57.100   libswscale      5.  5.100 /  5.  5.100   libswresample   3.  5.100 / 
    3.  5.100   libpostproc    55.  5.100 / 55.  5.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mov':   Metadata:
        major_brand     : qt
        minor_version   : 512
        compatible_brands: qt
        encoder         : Lavf58.62.100   Duration: 00:31:50.04, start: 0.000000, bitrate: 5309 kb/s
        Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 4151 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
        Metadata:
          handler_name    : Core Media Video
          encoder         : Lavc58.54.100 libx264
        Stream #0:1: Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
        Metadata:
          handler_name    : SoundHandler Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'b.mov':   Metadata:
        major_brand     : qt
        minor_version   : 512
        compatible_brands: qt
        encoder         : Lavf58.29.100   Duration: 00:00:10.01, start: 0.000000, bitrate: 67 kb/s
        Stream #1:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 64 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
        Metadata:
          handler_name    : VideoHandler
          encoder         : Lavc58.54.100 libx264

Thank you.

question from:https://stackoverflow.com/questions/65904567/concatenating-two-mov-files-results-in-identical-sized-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Problems

Your inputs have some different attributes, but they need to be the same to concatenate:

  • The timescales (30k vs 11988) are different. This is probably due to a.mov having 30000/1001 proper NTSC frame rate and b.mov is 29.97. ffprobe can confirm this. The ffmpeg output is for "entertainment purposes only" and reports an abbreviated frame rate.

  • a.mov has audio, but b.mov does not.

To fix it

  1. Re-mux b.mov and add silent audio:

    ffmpeg -i b.mov -f lavfi -i anullsrc=r=48000:cl=mono -c:v copy -c:a pcm_s24le -video_track_timescale 30k -shortest b2.mov
    
  2. Then update list.txt with the new file (b2.mov).

  3. Concatenate:

    ffmpeg -safe 0 -f concat -i list.txt -c copy c.mov
    

Options

  • -f lavfi -i anullsrc=r=48000:cl=mono makes silent audio with 48000 sample rate and mono channel layout. This matches the sample rate and channel layout of a.mov. You can't concatenate an input with audio with an input that has no audio, so this just creates silent filler/dummy audio.

  • -c:v copy stream copy the video.

  • -c:a pcm_s24le chooses the encoder pcm_s24le to create an audio format that matches a.mov.

  • -video_track_timescale 30k sets video timescale to match a.mov. See What is video timescale, timebase, or timestamp in ffmpeg?

  • -shortest ends the output whenever the shortest input ends. Needed because I did not set a duration for anullsrc (using -shortest is easier).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...