ffmpeg record and play multiplex stream (multi-program stream)

ffmpeg records and broadcasts multiplexed streams (multi-program streams).
The playback here means recording.
The recording is saved as a file, and the playback is sent out using the udp protocol. Therefore, the meaning of playback here is still the meaning of recording.

Multiplexed stream recording:
If there is a multiplexed stream, including 4 programs, as follows:
ffmpeg -probesize 10000000 -analyzeduration 5000000 -i multiVideo.ts
Program 1
  Stream #0:0[0x259]: Video: h264 (High) ([ 27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 90k tbn, 48 tbc Stream #
  0 :1[0x321](eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s

Program 2
  Stream #0:5[0x25a]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
  Stream #0:4[0x322](eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s
Program 3
  Stream #0:6[0x25b]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
  Stream #0:2[0x323](eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s
Program 4
  Stream #0:7[0x25c]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
  Stream #0:3[0x324](eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s

See? The sequence of stream index numbers is a bit messy, which will lead to higher skill in stream mapping! Simply typing and not carefully specifying the stream order may not meet your requirements. The complete recording command: ffmpeg
-y
- i multiVideo.ts -map 0:p:1 -map 0:p:2 -map 0:p:3 -map 0:p:4 -c copy -program title=A1:st=0:st=1 -program title=A2:st=2:st=3 -program title=A3:st=4:st=5 -program title=A4:st=6:st=7 t1.ts What does this mean? Use map
to
select Stream, including audio stream, video stream, subtitle stream.
-map 0:v video stream of file 0
-map 0:a audio stream of file 0            
-map 0:2 third stream of file 0, index number, specify one stream, but there is a disadvantage that the index of the udp stream may be inconsistent with the index of the next time
-map 0:p:1 All streams whose program number is 1 in file 0, this specifies all streams of a certain program, generally 2 The stream with the small index number will be in the front.
-map 0:i:0x100 The stream ID of file 0 is 0x100. This is the most detailed and specifies a specific stream.
Since all these streams want to be output, it can be abbreviated as -map 0 Indicates that the first file stream is all selected, but it is described one by one
-map 0:p:1 -map 0:p:2 -map 0:p:3 -map 0:p:4 The sequence of streams mapped In the same way, to ensure correctness, it is better to write multi-point
sequence control, and more detailed is to directly specify the stream PID.

Use program to specify which programs to output
-program [title=title:][program_num=program_num:]st=stream[:st=stream...] (output)
    Creates a program with the specified title, program_num and adds the specified stream (s) to it.
The st here specifies the index of the input stream to see how the input stream is arranged. (So the mapping order of each program is easier to control, and the default order of -map 0 may be a bit messy) If
recording If you want to include multiple programs, you must use the -program option to specify, and you must add title and st instructions, otherwise the effect will not be achieved. It depends on the actual
combat.
In the program, the audio sequence number of p2, p3, and p4 comes first, and the video sequence number follows. Not what I want. Need to further decompose -map 0:p:1 into -map 0:i:xxx for accurate control!!!
But it is enough, so be it.

title is metadata, indicating the program Servie_name


1. Single-stream test
ffmpeg -i test1.ts -c copy -program title=A1 t.ts
title is a piece of metadata, which will represent the service_name in the stream, default Service01
ffmpeg -y -i multiVideo.ts -c copy -map 0 :p:1 -program title=A1:st=100:st=101 p1.ts
After clarifying the above problems, you can choose streams at will, package them for recording or send them out.
2. Unpack the multiplexed streams into 4 single stream
ffmpeg -y -i multiVideo.ts -c copy -map 0:p:1 p1.ts -c copy -map 0:p:2 p2.ts -c copy -map 0:p:3 p3.ts -c copy -map 0:p:4 p4.ts
I checked p2.ts, p3.ts, and p4.ts, the audio stream is in the front, and the video stream is in the back, because the serial number of the audio stream in multiVideo.ts is small, so It is ranked at 0, so it does not affect the playback.
If you want to make the video in front according to the tradition, you can use -map 0:i:xx to specify the order accurately
. The key is to use -map to map different streams. With a sequence, use -program to select it, so as to complete the mapping from multi-program to multi-program!

おすすめ

転載: blog.csdn.net/hejinjing_tom_com/article/details/129345505