[FFmpeg-user] How to split and then concatenate a video file?

Žygimantas Bruzgys un1x0nly at gmail.com
Tue Feb 19 13:15:46 CET 2013


On Tue, Feb 19, 2013 at 12:54 PM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
> Command lines and complete, uncut console output
> missing.

No problems, here you go:

1) Splitting the video:

zybru at hp-6530b-bs:~/Desktop$ ffmpeg -i small.mp4 -f segment -c copy
-segment_time 2 -map 0 out%03d.mp4
ffmpeg version N-49277-g7003d65 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan 25 2013 14:08:54 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-shared --enable-gpl --enable-nonfree
--enable-libfaac --enable-libx264 --enable-libxvid --enable-libmp3lame
--enable-libtheora --enable-libopenjpeg --disable-stripping
--enable-debug=3 --extra-cflags=-gstabs+ --disable-optimizations
  libavutil      52. 15.103 / 52. 15.103
  libavcodec     54. 90.100 / 54. 90.100
  libavformat    54. 61.104 / 54. 61.104
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 33.100 /  3. 33.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.61.100
  Duration: 00:01:00.00, start: 0.000000, bitrate: 1361 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], 1239 kb/s, 24 fps, 24 tbr, 16k tbn, 48
tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 128 kb/s
    Metadata:
      handler_name    : SoundHandler
Output #0, segment, to 'out%03d.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.61.104
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], q=2-31, 1239 kb/s, 24 fps, 90k tbn, 24
tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 128 kb/s
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 1424 fps=0.0 q=-1.0 Lsize=N/A time=00:01:00.00 bitrate=N/A
video:8974kB audio:938kB subtitle:0 global headers:0kB muxing overhead
-100.000217%

2) Concatenating the video:

zybru at hp-6530b-bs:~/Desktop$ cat concat.lst | head -n 2; cat
concat.lst | tail -n 2
file 'out000.mp4'
file 'out001.mp4'
file 'out028.mp4'
file 'out029.mp4'

zybru at hp-6530b-bs:~/Desktop$ ffmpeg -f concat -i concat.lst -c copy joined.mp4
ffmpeg version N-49277-g7003d65 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan 25 2013 14:08:54 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-shared --enable-gpl --enable-nonfree
--enable-libfaac --enable-libx264 --enable-libxvid --enable-libmp3lame
--enable-libtheora --enable-libopenjpeg --disable-stripping
--enable-debug=3 --extra-cflags=-gstabs+ --disable-optimizations
  libavutil      52. 15.103 / 52. 15.103
  libavcodec     54. 90.100 / 54. 90.100
  libavformat    54. 61.104 / 54. 61.104
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 33.100 /  3. 33.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[concat @ 0x1760f80] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from 'concat.lst':
  Duration: 00:00:00.67, start: 0.000000, bitrate: 6 kb/s
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], 1496 kb/s, 20.63 fps, 24 tbr, 12288
tbn, 48 tbc
    Stream #0:1: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo,
fltp, 126 kb/s
Output #0, mp4, to 'joined.mp4':
  Metadata:
    encoder         : Lavf54.61.104
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], q=2-31, 1496 kb/s, 20.63 fps, 12288
tbn, 12288 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 126 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
Invalid SampleDelta in STTS -56250  9096kB time=00:01:02.29
bitrate=1196.1kbits/s
frame= 1424 fps=389 q=-1.0 Lsize=    9970kB time=00:01:07.42
bitrate=1211.3kbits/s
video:8974kB audio:938kB subtitle:0 global headers:0kB muxing overhead 0.588816%

zybru at hp-6530b-bs:~/Desktop$ ffprobe joined.mp4
ffprobe version N-49277-g7003d65 Copyright (c) 2007-2013 the FFmpeg developers
  built on Jan 25 2013 14:08:54 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-shared --enable-gpl --enable-nonfree
--enable-libfaac --enable-libx264 --enable-libxvid --enable-libmp3lame
--enable-libtheora --enable-libopenjpeg --disable-stripping
--enable-debug=3 --extra-cflags=-gstabs+ --disable-optimizations
  libavutil      52. 15.103 / 52. 15.103
  libavcodec     54. 90.100 / 54. 90.100
  libavformat    54. 61.104 / 54. 61.104
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 33.100 /  3. 33.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x202b460] Invalid SampleDelta in STTS -729599
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x202b460] Invalid SampleDelta in STTS -2617339
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'joined.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.61.104
  Duration: 00:00:08.05, start: 0.000000, bitrate: 10142 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], 1101 kb/s, 21.34 fps, 24 tbr, 12288
tbn, 48 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 113 kb/s
    Metadata:
      handler_name    : SoundHandler

3) Mind the duration. So, I've later tried to fix the clip performing
a simple command:

zybru at hp-6530b-bs:~/Desktop$ ffmpeg -i joined.mp4 -c copy fixed.mp4
ffmpeg version N-49277-g7003d65 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan 25 2013 14:08:54 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-shared --enable-gpl --enable-nonfree
--enable-libfaac --enable-libx264 --enable-libxvid --enable-libmp3lame
--enable-libtheora --enable-libopenjpeg --disable-stripping
--enable-debug=3 --extra-cflags=-gstabs+ --disable-optimizations
  libavutil      52. 15.103 / 52. 15.103
  libavcodec     54. 90.100 / 54. 90.100
  libavformat    54. 61.104 / 54. 61.104
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 33.100 /  3. 33.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1409f40] Invalid SampleDelta in STTS -729599
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x1409f40] Invalid SampleDelta in STTS -2617339
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'joined.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.61.104
  Duration: 00:00:08.05, start: 0.000000, bitrate: 10142 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], 1101 kb/s, 21.34 fps, 24 tbr, 12288
tbn, 48 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 113 kb/s
    Metadata:
      handler_name    : SoundHandler
Output #0, mp4, to 'fixed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.61.104
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], q=2-31, 1101 kb/s, 21.34 fps, 12288
tbn, 12288 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz,
stereo, 113 kb/s
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 1424 fps=0.0 q=-1.0 Lsize=    9970kB time=00:01:07.42
bitrate=1211.3kbits/s
video:8974kB audio:938kB subtitle:0 global headers:0kB muxing overhead 0.588816%

After this, ffprobe reports:

zybru at hp-6530b-bs:~/Desktop$ ffprobe fixed.mp4
ffprobe version N-49277-g7003d65 Copyright (c) 2007-2013 the FFmpeg developers
  built on Jan 25 2013 14:08:54 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-shared --enable-gpl --enable-nonfree
--enable-libfaac --enable-libx264 --enable-libxvid --enable-libmp3lame
--enable-libtheora --enable-libopenjpeg --disable-stripping
--enable-debug=3 --extra-cflags=-gstabs+ --disable-optimizations
  libavutil      52. 15.103 / 52. 15.103
  libavcodec     54. 90.100 / 54. 90.100
  libavformat    54. 61.104 / 54. 61.104
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 33.100 /  3. 33.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x19fe460] Invalid SampleDelta in STTS -8183
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'fixed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.61.104
  Duration: 00:01:07.40, start: 0.000000, bitrate: 1211 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1920x818 [SAR 1:1 DAR 960:409], 1101 kb/s, 21.34 fps, 24 tbr, 12288
tbn, 48 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 113 kb/s
    Metadata:
      handler_name    : SoundHandler

I may upload small.mp4 if needed.

Žygimantas


More information about the ffmpeg-user mailing list