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

Žygimantas Bruzgys un1x0nly at gmail.com
Fri Feb 22 13:40:55 CET 2013


Another interesting observation:
If you demux video to a separate mp4 file, segment it, transcode it,
concatenate it, and mux it back with audio, the resulting video is
flawless and plays without any issues.

Here's the output:

zybru at hp-6530b-bs:~/Desktop$ ffmpeg -i run-h264-aac.mp4 -c copy -an video.mp4
ffmpeg version N-50129-g951d39f Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 20 2013 14:47:49 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libtheora --enable-libvorbis --enable-libx264
--enable-nonfree --enable-version3 --enable-x11grab
--disable-stripping --enable-debug=3 --extra-cflags=-gstabs+
--disable-optimizations
  libavutil      52. 17.102 / 52. 17.102
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.103 /  3. 38.103
  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 'run-h264-aac.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
  Duration: 00:01:20.28, start: 0.021333, bitrate: 1921 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
720x576 [SAR 64:45 DAR 16:9], 1795 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 120 kb/s
    Metadata:
      handler_name    : SoundHandler
Output #0, mp4, to 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p,
720x576 [SAR 64:45 DAR 16:9], q=2-31, 1795 kb/s, 25 fps, 12800 tbn,
12800 tbc
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 2006 fps=0.0 q=-1.0 Lsize=   17612kB time=00:01:20.14
bitrate=1800.3kbits/s
video:17588kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.137361%

zybru at hp-6530b-bs:~/Desktop$ ffmpeg -i video.mp4 -f segment
-segment_time 3 -map 0 -c copy out%03d.mp4
ffmpeg version N-50129-g951d39f Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 20 2013 14:47:49 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libtheora --enable-libvorbis --enable-libx264
--enable-nonfree --enable-version3 --enable-x11grab
--disable-stripping --enable-debug=3 --extra-cflags=-gstabs+
--disable-optimizations
  libavutil      52. 17.102 / 52. 17.102
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.103 /  3. 38.103
  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 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
  Duration: 00:01:20.24, start: 0.021016, bitrate: 1798 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
720x576 [SAR 64:45 DAR 16:9], 1795 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
tbc
    Metadata:
      handler_name    : VideoHandler
Output #0, segment, to 'out%03d.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p,
720x576 [SAR 64:45 DAR 16:9], q=2-31, 1795 kb/s, 25 fps, 90k tbn, 25
tbc
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 2006 fps=0.0 q=-1.0 Lsize=N/A time=00:01:20.16 bitrate=N/A
video:17588kB audio:0kB subtitle:0 global headers:0kB muxing overhead
-100.000122%


<Transcode to h264/acc with -vf scale=iw/2:-1>

zybru at hp-6530b-bs:~/Desktop$ ffmpeg -f concat -i concat.lst -c copy int.mp4
ffmpeg version N-50129-g951d39f Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 20 2013 14:47:49 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libtheora --enable-libvorbis --enable-libx264
--enable-nonfree --enable-version3 --enable-x11grab
--disable-stripping --enable-debug=3 --extra-cflags=-gstabs+
--disable-optimizations
  libavutil      52. 17.102 / 52. 17.102
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.103 /  3. 38.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[concat @ 0x33b1fc0] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from 'concat.lst':
  Duration: 00:00:00.01, start: 0.000000, bitrate: 561 kb/s
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p,
360x288 [SAR 64:45 DAR 16:9], 562 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
tbc
Output #0, mp4, to 'int.mp4':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p,
360x288 [SAR 64:45 DAR 16:9], q=2-31, 562 kb/s, 25 fps, 12800 tbn,
12800 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 2006 fps=0.0 q=-1.0 Lsize=    2929kB time=00:01:20.12 bitrate=
299.5kbits/s
video:2905kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.830710%

zybru at hp-6530b-bs:~/Desktop$ ffmpeg -i run-h264-aac.mp4 -i int.mp4 -c
copy -map 0:1 -map 1 joined.mp4
ffmpeg version N-50129-g951d39f Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 20 2013 14:47:49 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libtheora --enable-libvorbis --enable-libx264
--enable-nonfree --enable-version3 --enable-x11grab
--disable-stripping --enable-debug=3 --extra-cflags=-gstabs+
--disable-optimizations
  libavutil      52. 17.102 / 52. 17.102
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.103 /  3. 38.103
  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 'run-h264-aac.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
  Duration: 00:01:20.28, start: 0.021333, bitrate: 1921 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
720x576 [SAR 64:45 DAR 16:9], 1795 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 120 kb/s
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'int.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
  Duration: 00:01:20.24, start: 0.000000, bitrate: 299 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
360x288 [SAR 64:45 DAR 16:9], 296 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
tbc
    Metadata:
      handler_name    : VideoHandler
Output #0, mp4, to 'joined.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
    Stream #0:0(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz,
stereo, 120 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:1(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p,
360x288 [SAR 64:45 DAR 16:9], q=2-31, 296 kb/s, 25 fps, 12800 tbn,
12800 tbc
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 2006 fps=0.0 q=-1.0 Lsize=    4144kB time=00:01:20.27 bitrate=
422.9kbits/s
video:2905kB audio:1178kB subtitle:0 global headers:0kB muxing
overhead 1.489719%

zybru at hp-6530b-bs:~/Desktop$ ffprobe joined.mp4
ffprobe version N-50129-g951d39f Copyright (c) 2007-2013 the FFmpeg developers
  built on Feb 20 2013 14:47:49 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libtheora --enable-libvorbis --enable-libx264
--enable-nonfree --enable-version3 --enable-x11grab
--disable-stripping --enable-debug=3 --extra-cflags=-gstabs+
--disable-optimizations
  libavutil      52. 17.102 / 52. 17.102
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.103 /  3. 38.103
  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 'joined.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.100
  Duration: 00:01:20.30, start: 0.000000, bitrate: 422 kb/s
    Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 120 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
360x288 [SAR 64:45 DAR 16:9], 296 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
tbc
    Metadata:
      handler_name    : VideoHandler


Žygimantas Bruzgys


More information about the ffmpeg-user mailing list