haitham mohamed
haitham mohamed

Reputation: 11

how to extract elementary stream from transport stream

i have .ts file looks like the following

Input #0, mpegts, from 'i.ts':
  Duration: 00:00:36.32, start: 28752.398067, bitrate: 57694 kb/s
  Program 50 
    Metadata:
      service_name    : aaa HD
      service_provider: 
    Stream #0:51[0x1f5]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
    Stream #0:52[0x1f6]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp
  Program 51 
    Metadata:
      service_name    : b Music HD
      service_provider: 
    Stream #0:16[0x1ff]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
    Stream #0:17[0x200]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp
  Program 52 
    Metadata:
      service_name    : c ch HD
      service_provider: 
    Stream #0:14[0x209]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
    Stream #0:15[0x20a]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp
  Program 1510 
    Metadata:
      service_name    : asd
      service_provider: xyz
    Stream #0:18[0x5e7]: Video: h264 ([27][0][0][0] / 0x001B), none, 90k tbr, 90k tbn, 180k tbc
    Stream #0:19[0x5e8]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels, fltp

i need to extract one video stream and its audio stream from this file for example related to program 50 i tried

ffmpeg -i i.ts -map 0:51 output.mp4 

but i got this error

Stream mapping:
  Stream #0:51 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
Cannot determine format of input stream 0:51 after EOF
Error marking filters as finished
Conversion failed!

Upvotes: 0

Views: 2783

Answers (1)

Rotem
Rotem

Reputation: 32094

I found a solution here

For mapping the whole programs, the syntax is:

ffmpeg -i i.ts -c:v copy -c:a copy -map 0:p:51 output.mp4

I can't verify that solution is actually working with your .ts file.

I created the following sample, that builds a .ts file with two programs, and then extracts each program to .mp4 file:

ffmpeg -y -r 10 -f lavfi -i testsrc=rate=10:size=160x120 -f lavfi -i sine=frequency=1000 -t 5 -c:v libx264 -c:a aac in1.mp4
ffmpeg -y -r 10 -f lavfi -i mandelbrot=rate=10:size=160x120 -f lavfi -i sine=frequency=300 -t 5 -c:v libx264 -c:a aac in2.mp4
ffmpeg -y -i in1.mp4 -i in2.mp4 -map 0:0 -map 0:1 -map 1:0 -map 1:1 -program title=ProgOne:st=0:st=1 -program title=ProgTwo:st=2:st=3 -c:v copy -c:a copy in.ts
ffmpeg -y -i in.ts -c:v copy -c:a copy -map 0:p:1 output1.mp4
ffmpeg -y -i in.ts -c:v copy -c:a copy -map 0:p:2 output2.mp4
  • 1st command builds video test pattern with high frequency beep (output: in1.mp4).
  • 2nd command builds video Mandelbrot pattern with low frequency beep (output: in2.mp4).
  • 3rd command builds transport stream with two programs (output: in.ts).
  • 4th command extracts first program (output: output1.mp4).
  • 5th command extracts second program (output: output2.mp4).

Upvotes: 0

Related Questions