利用ffmpeg取出ts流中特定的program
https://trac.ffmpeg.org/wiki/Map
http://stackoverflow.com/questions/43845382/ffmpeg-retrieve-a-specific-program-from-ts-file/43846235#43846235
Example 8
MPEG stream selection:
The tricky part with selecting from MPEG TS is it may contain multiple streams/channels, and if you are receiving "live data" just specifying an index might not work because it can change from run to run, so
ffmpeg -i INPUT -map 0:6 OUTPUT # might not work the same every run, DO NOT USE THIS WAY!
Assuming your file is MPEG, you can run "ffmpeg -i INPUT" (not specify an output) to see what program id's and stream id's it contains, like this example (probesize and analyzeduration specified to help "make sure" it picks up all the streams in it, may not be always needed)
$ ffmpeg -probesize 50M -analyzeduration 50M -i INPUT ... Input #0, mpegts, from 'INPUT': Duration: N/A, start: 22159.226833, bitrate: N/A Program 1344 Metadata: service_name : 7 Digital service_provider: Seven Network Stream #0:0[0x401]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 14950 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc Stream #0:1[0x402](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 256 kb/s Program 1346 Metadata: service_name : 7TWO service_provider: Seven Network Stream #0:3[0x406]: Unknown: none ([5][0][0][0] / 0x0005) Stream #0:6[0x421]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 14950 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc Stream #0:7[0x422](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s Stream #0:8[0x424](eng): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006), 492x250 Stream #0:4[0x499]: Unknown: none ([11][0][0][0] / 0x000B)
you could specify desired streams by program id:
ffmpeg -i INPUT -map 0:p:1344 OUTPUT # pulls in both inputs from program 1344, channel "7 Digital" in this case
or specify a child stream:
ffmpeg -i INPUT -map i:0x401 OUTPUT # pulls in the single input stream with PID (MPEG Packet ID [stream identifier]) 0x401 from wherever it is found, in this case its a video stream in "7 Digital"
or similar, see other specifier examples. Note if you have "unknown" streams in there you may need to add the -ignore_unknown flag as well.
Also note that if your input stream contains multiple program id's, you can record simultaneously from various of them, using the same FFmpeg instance and the map commands described here.
解決會自動transcode的問題
FFmpeg, by default, will transcode to the default codecs for the output container. Add
-codec copy
or -c copy
i.e.ffmpeg -i INPUT -c copy -map 0:p:1344 OUTPUT
留言
張貼留言