FFmpeg command line parameter map to select audio and video streaming

FFmpeg command line parameter map to select audio and video streaming


Introduction

  • -mapParameter tells ffmpeg from the input source 选择/拷贝which streamflows to the output, a plurality of audio and video streams may be selected from the input source as the output.

  • Without -mapparameters, ffmpeg default input source from the video stream and audio stream for each selected stream.

  • Sequentially output stream stream / file depends on the command line -mapparameter sequence.


By default

By default (do not use -mapparameters), such as:

ffmpeg -i 0001.ts -c copy -f mpegts  udp://192.168.1.100&pkt_size=1316

FFmpeg find default [from all input streams a video input stream the highest quality [] and a highest quality audio input stream ], udp and copy output stream output stream. Other flow essentially will be discarded.

If a command to display the map using the same operation as the above command, its command is as follows:

ffmpeg -i 0001.ts \
        -map single_highest_quality_video_stream_from_all_inputs \
        -map single_highest_quality_audio_stream_from_all_inputs \
        -c copy -f mpegts  "udp://192.168.1.100:1234?pkt_size=1316"

Here the output will have two streams, one audio, one video.


Specified input stream audio and video streams

Example, 0001.ts a single video stream, multiple audio streams of information as follows:

  1. Stream #0:0 Video stream
  2. Stream #0:1~ Stream #0:3Is an audio stream
  3. Stream #0:4 It is the subtitle stream
Input #0, mpegts, from '0001.ts':
  Duration: 00:04:46.23, start: 57251.747478, bitrate: 5861 kb/s
  Program 34 
    Metadata:
      service_name    : Test TV HD
      service_provider: TV5
    Stream #0:0[0x53d]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x53e](THA): Audio: aac_latm (HE-AACv2) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
    Stream #0:2[0x53f](QAA): Audio: aac_latm (HE-AACv2) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
    Stream #0:3[0x540](NAR): Audio: aac_latm (LC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
    Stream #0:4[0x541](tha): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
01 If you want to specify all the way to take multiple video streams and multiple audio streams, how to deal with it?

The following command:

-map 0:0 -map 0:2

Select the input source Stream #0:0of the video stream, Stream #0:2audio stream, video and audio streaming copy the selected output to the output stream udp

ffmpeg -i 0001.ts -map 0:0 -map 0:2 -c copy -f mpegts  "udp://192.168.1.100:1234?pkt_size=1316"
02 If you want to specify take a single video streams and multi-channel audio streams, how to deal with it?

The following command:

-map 0:0 -map 0:1 -map 0:2 -map 0:3

Select the input source Stream #0:0video stream Stream #0:0, Stream #0:1and Stream #0:3the three audio streams, the audio and video output stream to copy the selected output stream udp

ffmpeg -i 0001.ts -map 0:0 -map 0:1 -map 0:2 -map 0:3 \ 
       -c copy -f mpegts  "udp://192.168.1.100:1234?pkt_size=1316"
03 If you want to take all the video and audio streams, how to deal with it?

The following command:

-map 0:a -map 0:v

Select all the input sources and all audio video streams, copy all audio and video output stream to the stream udp

ffmpeg -i 0001.ts -map 0:a -map 0:v -c copy -f mpegts  "udp://192.168.1.100:1234?pkt_size=1316"
04 If you want to take all streams (including subtitle stream, etc.), how to deal with it?

The following command:

-map 0

Selecting an input source for all streams, the stream to copy all udp stream

ffmpeg -i 0001.ts -map 0 -c copy -f mpegts  "udp://192.168.1.100:1234?pkt_size=1316"

Specified input stream into multiple streams of audio and video encoding format

Sometimes when dealing with multiple video input sources and multiple audio streams, want to do different encoding processes for different audio and video streaming

The following command:

  • The Stream #0:0video stream is duplicated copies
  • The Stream #0:1and Stream #0:2audio stream copy replication
  • The Stream #0:2audio stream is encoded mp3 format (128kbps)
  • The Stream #0:4subtitle stream copy Copy
fffmpeg -i 0001.ts -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 \
        - c:v copy \
        - c:a:0 copy \
        - c:a:1 copy \
        - c:a:2 libmp3lame -b:a:2 128k \
        - c:s copy \
        -f mpegts  "udp://192.168.1.100:1234?pkt_size=1316"

Guess you like

Origin www.cnblogs.com/xiaolincoding/p/11367442.html