12/31/2016

Copy all Streams of Media using ffmpeg



FAQ

  • How to copy all streams of some media using ffmpeg
  • Preserve all streams of some media, while spliting media
  • Copy selected streams of media using ffmpeg

Generally media files has two streams, one for video and other one for audio, but when your media file has multiple streams, and you want to copy all those streams to some other media file when you trying to cut or split specific parts from media file.

Example 1

I have recorded some video using TechSmith CamTasia Studio, and it has more than two streams, and i wanna split this into multiple parts, so that i can easily edit in CamTasia Video Editor, and i am using ffmpeg for this.

Case 1 [ Let me show you details of this Media File ]

C:\Users\someone\Camtasia Studio )
=$ ffprobe.exe "Rec 12-30-16.trec"
ffprobe version N-82759-g1f5630a Copyright (c) 2007-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --ena
ble-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-
libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enab
le-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-li
bopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspe
ex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
 --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzi
mg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 41.101 / 55. 41.101
  libavcodec     57. 66.109 / 57. 66.109
  libavformat    57. 58.101 / 57. 58.101
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Rec 12-30-16.trec':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2016-12-30T03:58:26.000000Z
  Duration: 00:21:29.64, start: 0.000000, bitrate: 3103 kb/s
    Stream #0:0(und): Video: tscc2 (tsc2 / 0x32637374), yuv444p, 1364x768, 2585 kb/s, 26.25 fps, 30 tbr, 30 tbn, 30 tbc
(default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
    Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z

Case 2 [ Cut Marked portion from this Media File ]

C:\Users\someone\Camtasia Studio )
=$ ffmpeg.exe -i "Rec 12-30-16.trec" -ss 150 -t 200 -map 0 -codec copy "Rec 12-30-16
.trec.0.avi"
ffmpeg version N-82759-g1f5630a Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --ena
ble-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-
libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enab
le-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-li
bopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspe
ex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
 --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzi
mg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 41.101 / 55. 41.101
  libavcodec     57. 66.109 / 57. 66.109
  libavformat    57. 58.101 / 57. 58.101
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Rec 12-30-16.trec':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2016-12-30T03:58:26.000000Z
  Duration: 00:21:29.64, start: 0.000000, bitrate: 3103 kb/s
    Stream #0:0(und): Video: tscc2 (tsc2 / 0x32637374), yuv444p, 1364x768, 2585 kb/s, 26.25 fps, 30 tbr, 30 tbn, 30 tbc
(default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
    Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
Output #0, avi, to 'Rec 12-30-16.trec.0.avi':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    ISFT            : Lavf57.58.101
    Stream #0:0(und): Video: tscc2 (tsc2 / 0x32637374), yuv444p, 1364x768, q=2-31, 2585 kb/s, 26.25 fps, 30 tbr, 30 tbn,
 30 tbc (default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
    Stream #0:1(und): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 44100 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
    Stream #0:2(und): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 44100 Hz, stereo, fltp, 253 kb/s (default)
    Metadata:
      creation_time   : 2016-12-30T03:58:26.000000Z
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
frame= 5365 fps=1520 q=-1.0 Lsize=   58364kB time=00:03:20.00 bitrate=2390.6kbits/s speed=56.7x
video:45405kB audio:12387kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.989971%

Case 3 [ Take a look at streams inside Splited Media file ]

C:\Users\someone\Camtasia Studio )
=$ ffprobe.exe "Rec 12-30-16.trec.0.avi"
ffprobe version N-82759-g1f5630a Copyright (c) 2007-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --ena
ble-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-
libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enab
le-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-li
bopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspe
ex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
 --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzi
mg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 41.101 / 55. 41.101
  libavcodec     57. 66.109 / 57. 66.109
  libavformat    57. 58.101 / 57. 58.101
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, avi, from 'Rec 12-30-16.trec.0.avi':
  Metadata:
    encoder         : Lavf57.58.101
  Duration: 00:03:20.02, start: 0.000000, bitrate: 2390 kb/s
    Stream #0:0: Video: tscc2 (tsc2 / 0x32637374), yuv444p, 1364x768, 1860 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
    Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 44100 Hz, stereo, fltp, 253 kb/s
    Stream #0:2: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 44100 Hz, stereo, fltp, 253 kb/s

Result

  • Now I can use this splited media file in CamTasia Video Editor
  • ffmpeg is OpenSource and Free to use.
  • You can download ffmpeg for Windows from https://ffmpeg.zeranoe.com/builds/
  • -map 0 parameter force ffmpeg to select all streams inside media file
  • -codec copy parameter is used to copy selected streams from media file
  • -ss time parameter is used to specify, starting marker, its value can be either in seconds or hh:mm:ss.ssss format.
  • -t time parameter is used to specify, ending marked, its value type is same as -ss parameter value.

OK friends, If anything left unexplained, you can comment below in comment box, Thanks


Post a Comment