首页 > 其他分享 >ffmpeg Streamcopy

ffmpeg Streamcopy

时间:2024-11-10 10:42:06浏览次数:5  
标签:ffmpeg stream mkv mp4 Streamcopy output elementary input

The simplest pipeline in ffmpeg is single-stream streamcopy, that is copying one input elementary stream’s packets without decoding, filtering, or encoding them. As an example, consider an input file called INPUT.mkv with 3 elementary streams, from which we take the second and write it to file OUTPUT.mp4. A schematic representation of such a pipeline looks like this:

┌──────────┬─────────────────────┐
│ demuxer  │                     │ unused
╞══════════╡ elementary stream 0 ├────────╳
│          │                     │
│INPUT.mkv ├─────────────────────┤          ┌──────────────────────┬───────────┐
│          │                     │ packets  │                      │   muxer   │
│          │ elementary stream 1 ├─────────⮞│  elementary stream 0 ╞═══════════╡
│          │                     │          │                      │OUTPUT.mp4 │
│          ├─────────────────────┤          └──────────────────────┴───────────┘
│          │                     │ unused
│          │ elementary stream 2 ├────────╳
│          │                     │
└──────────┴─────────────────────┘

The above pipeline can be constructed with the following commandline:

ffmpeg -i INPUT.mkv -map 0:1 -c copy OUTPUT.mp4

In this commandline

  • there is a single input INPUT.mkv;
  • there are no input options for this input;
  • there is a single output OUTPUT.mp4;
  • there are two output options for this output:
    • -map 0:1 selects the input stream to be used - from input with index 0 (i.e. the first one) the stream with index 1 (i.e. the second one);
    • -c copy selects the copy encoder, i.e. streamcopy with no decoding or encoding.

Streamcopy is useful for changing the elementary stream count, container format, or modifying container-level metadata. Since there is no decoding or encoding, it is very fast and there is no quality loss. However, it might not work in some cases because of a variety of factors (e.g. certain information required by the target container is not available in the source). Applying filters is obviously also impossible, since filters work on decoded frames.

More complex streamcopy scenarios can be constructed - e.g. combining streams from two input files into a single output:

┌──────────┬────────────────────┐         ┌────────────────────┬───────────┐
│ demuxer 0│                    │ packets │                    │   muxer   │
╞══════════╡elementary stream 0 ├────────⮞│elementary stream 0 ╞═══════════╡
│INPUT0.mkv│                    │         │                    │OUTPUT.mp4 │
└──────────┴────────────────────┘         ├────────────────────┤           │
┌──────────┬────────────────────┐         │                    │           │
│ demuxer 1│                    │ packets │elementary stream 1 │           │
╞══════════╡elementary stream 0 ├────────⮞│                    │           │
│INPUT1.aac│                    │         └────────────────────┴───────────┘
└──────────┴────────────────────┘

that can be built by the commandline

ffmpeg -i INPUT0.mkv -i INPUT1.aac -map 0:0 -map 1:0 -c copy OUTPUT.mp4

The output -map option is used twice here, creating two streams in the output file - one fed by the first input and one by the second. The single instance of the -c option selects streamcopy for both of those streams. You could also use multiple instances of this option together with Stream specifiers to apply different values to each stream, as will be demonstrated in following sections.

A converse scenario is splitting multiple streams from a single input into multiple outputs:

┌──────────┬─────────────────────┐          ┌───────────────────┬───────────┐
│ demuxer  │                     │ packets  │                   │ muxer 0   │
╞══════════╡ elementary stream 0 ├─────────⮞│elementary stream 0╞═══════════╡
│          │                     │          │                   │OUTPUT0.mp4│
│INPUT.mkv ├─────────────────────┤          └───────────────────┴───────────┘
│          │                     │ packets  ┌───────────────────┬───────────┐
│          │ elementary stream 1 ├─────────⮞│                   │ muxer 1   │
│          │                     │          │elementary stream 0╞═══════════╡
└──────────┴─────────────────────┘          │                   │OUTPUT1.mp4│
                                            └───────────────────┴───────────┘

built with

ffmpeg -i INPUT.mkv -map 0:0 -c copy OUTPUT0.mp4 -map 0:1 -c copy OUTPUT1.mp4

Note how a separate instance of the -c option is needed for every output file even though their values are the same. This is because non-global options (which is most of them) only apply in the context of the file before which they are placed.

These examples can of course be further generalized into arbitrary remappings of any number of inputs into any number of outputs.

标签:ffmpeg,stream,mkv,mp4,Streamcopy,output,elementary,input
From: https://www.cnblogs.com/sathcal/p/18537703

相关文章

  • ffmpeg Trancoding
    Transcoding istheprocessofdecodingastreamandthenencodingitagain.Sinceencodingtendstobecomputationallyexpensiveandinmostcasesdegradesthestreamquality(i.e.itis lossy),youshouldonlytranscodewhenyouneedtoandperformstrea......
  • FFmpeg Filtering
    Whentranscoding,audioandvideostreamscanbefilteredbeforeencoding,witheitherasimpleorcomplexfiltergraph.3.3.1SimplefiltergraphsSimplefiltergraphsarethosethathaveexactlyoneinputandoutput,bothofthesametype(audioorvideo).......
  • FFmpeg Stream selection
    ffmpegprovidesthe-mapoptionformanualcontrolofstreamselectionineachoutputfile.Userscanskip-mapandletffmpegperformautomaticstreamselectionasdescribedbelow.The-vn/-an/-sn/-dnoptionscanbeusedtoskipinclusionofvideo,......
  • ffmpeg Synopsis
    1Synopsisffmpeg[global_options]{[input_file_options]-iinput_url}...{[output_file_options]output_url}...2Descriptionffmpegisauniversalmediaconverter.Itcanreadawidevarietyofinputs-includinglivegrabbing/recordingdevices-filter,......
  • About FFmpeg
    FFmpegistheleadingmultimediaframework,abletodecode,encode,transcode,mux,demux,stream,filterandplayprettymuchanythingthathumansandmachineshavecreated.Itsupportsthemostobscureancientformatsuptothecuttingedge.Nomatteri......
  • FFmpeg Libraries for developers
    libavutilisalibrarycontainingfunctionsforsimplifyingprogramming,includingrandomnumbergenerators,datastructures,mathematicsroutines,coremultimediautilities,andmuchmore.libavcodecisalibrarycontainingdecodersandencodersforaudio......
  • php使用ffmpeg实现向视频中添加文字字幕的方法
    这篇文章主要介绍了PHP使用ffmpeg给视频增加字幕显示的方法,实例分析了php操作ffmpeg给视频增加字母的技巧,具有一定参考借鉴价值,需要的朋友可以参考下。具体如下:$dir='./';if($handle=opendir($dir)){while(false!==($file=readdir($handle))){if(is_file($dir.$......
  • PHP中的FFmpeg安装及使用
    FFmpeg简介FFmpeg是视频处理最常用的开源软件。它功能强大,用途广泛,大量用于视频网站和商业软件(比如Youtube和iTunes),也是许多音频和视频格式的标准编码/解码实现。关于FFMPEG视音频编解码的知识可以参考大神雷霄骅的系列教程https://blog.csdn.net/leixiaohua1020/article/detai......
  • FFmpeg 简单介绍及使用
    1.简介FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开......
  • PHP ffmpeg 视频合并
    随着互联网的发展和视频技术的不断完善,视频在我们的生活中扮演着越来越重要的角色。但是,当前视频处理和编辑的需求也在不断增加,这就需要我们使用到一些专业的工具来帮助我们完成这项工作。其中,ffmpeg是一个非常流行的视频处理工具,它支持多种视频编解码格式,可以对视频进行编辑、剪......