[FFmpeg-user] Concat specific streams from 2 files

Hans Carlson forbyta at gmx.com
Mon Nov 7 00:23:02 EET 2016


Is there any way to concat (not merge) specific streams from 2 files 
without re-encoding?

For example, file #1 has a video stream and 4 audio streams and file #2 
has a video stream and 2 audio streams.  I want to concat the files 
together, but include ONLY the following:

   FILE-1: 0:0, 0:1, 0:5
   FILE-2: 0:0, 0:1, 0:2

I know I can do this with the concat filter, but I don't want to re-encode, 
so that's not an option.

I don't *think* there's a way to do this with the concat protocol, but 
please let me know if there is.

The concat demuxer seems like the best option, but either I don't know how 
to properly specify the streams (very likely) or it's just not possible 
(see below).  It looks to me like it tries to merge the streams instead of 
concat'ing.  But then it fails with a seg fault so maybe my input file 
isn't correct.

$ ffmpeg -f concat -i files.txt -codec copy -f vob TEST.mpg
ffmpeg version N-82261-g2d72ea6 Copyright (c) 2000-2016 the FFmpeg developers
   built with gcc 4.9.2 (GCC) 20150212 (Red Hat 4.9.2-6)
   configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-static --enable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-x11grab --disable-ffplay --disable-ffserver
   libavutil      55. 35.100 / 55. 35.100
   libavcodec     57. 66.101 / 57. 66.101
   libavformat    57. 57.100 / 57. 57.100
   libavdevice    57.  2.100 / 57.  2.100
   libavfilter     6. 66.100 /  6. 66.100
   libswscale      4.  3.100 /  4.  3.100
   libswresample   2.  4.100 /  2.  4.100
   libpostproc    54.  2.100 / 54.  2.100
Input #0, concat, from 'files.txt':
   Duration: N/A, start: 0.000000, bitrate: N/A
     Stream #0:0: Video: mpeg2video (Main), yuv420p(tv, bottom first), 720x480 [SAR 32:27 DAR 16:9], 29.67 fps, 59.94 tbr, 90k tbn, 90k tbc
     Stream #0:1: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
     Stream #0:2: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
     Stream #0:3: Video: mpeg2video (Main), yuv420p(tv, bottom first), 720x480 [SAR 32:27 DAR 16:9], 29.67 fps, 59.94 tbr, 90k tbn, 90k tbc
     Stream #0:4: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
     Stream #0:5: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
[vob @ 0x17db240] VBV buffer size not set, using default size of 130KB
If you want the mpeg file to be compliant to some specification
Like DVD, VCD or others, make sure you set the correct buffer size
Output #0, vob, to 'TEST.mpg':
   Metadata:
     encoder         : Lavf57.57.100
     Stream #0:0: Video: mpeg2video (Main), yuv420p(tv, bottom first), 720x480 [SAR 32:27 DAR 16:9], q=2-31, 29.67 fps, 59.94 tbr, 90k tbn, 90k tbc
     Stream #0:1: Audio: ac3, 48000 Hz, 5.1(side), 448 kb/s
Stream mapping:
   Stream #0:3 -> #0:0 (copy)
   Stream #0:4 -> #0:1 (copy)
Press [q] to stop, [?] for help
[vob @ 0x17db240] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
Segmentation fault (core dumped)

$ cat files.txt
stream
exact_stream_id 0x1E0
stream
exact_stream_id 0x80
stream
exact_stream_id 0x84
file TEST-1.mpg

stream
exact_stream_id 0x1E0
stream
exact_stream_id 0x80
stream
exact_stream_id 0x81
file TEST-2.mpg

$ ffmpeg -hide_banner -i TEST-1.mpg
Input #0, mpeg, from 'TEST-1.mpg':
   Duration: 00:00:10.11, start: 0.533367, bitrate: 8093 kb/s
     Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, bottom first), 720x480 [SAR 32:27 DAR 16:9], 29.67 fps, 59.94 tbr, 90k tbn, 59.94 tbc
     Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
     Stream #0:2[0x81]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
     Stream #0:3[0x82]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
     Stream #0:4[0x83]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
     Stream #0:5[0x84]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
At least one output file must be specified

$ ffmpeg -hide_banner -i TEST-2.mpg
Input #0, mpeg, from 'TEST-2.mpg':
   Duration: 00:00:10.11, start: 0.533367, bitrate: 4247 kb/s
     Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, bottom first), 720x480 [SAR 32:27 DAR 16:9], 31 fps, 59.94 tbr, 90k tbn, 59.94 tbc
     Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
     Stream #0:2[0x81]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
At least one output file must be specified


More information about the ffmpeg-user mailing list