If you have a transport stream file, but the PIDs in it are not what you desire use the following process to change them, resulting in a new TS file:
- Use
ffprobeto work out the "stream index" for each PID in the file
ffprobe ORIGINAL.ts
You are looking for the lines that begin with Stream #0:. The next number is the stream index. The number in the square brackets following it are the PID, in hex.
In the example below, stream index 0 is PID 6601 (0x19c9) and stream index 1 is PID 6602 (0x19ca):
Input #0, mpegts, from 'ORIGINAL.ts':
Duration: 00:02:00.66, start: 13972.198711, bitrate: 3616 kb/s
Program 17539
Metadata:
service_name : BBC ONE Sth HD
service_provider:
Stream #0:0[0x19c9]: 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
Stream #0:1[0x19ca](eng): Audio: aac_latm (LC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
Stream #0:2[0x19ce](eng): Audio: aac_latm (HE-AACv2) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp (visual impaired) (descriptions) (dependent)
Stream #0:3[0x19cd](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
Stream #0:4[0x1c86]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:5[0x1c97]: Unknown: none ([11][0][0][0] / 0x000B)
Stream #0:6[0x1bc4]: Unknown: none ([5][0][0][0] / 0x0005)
Stream #0:7[0x1bc6]: Unknown: none ([5][0][0][0] / 0x0005)
- Use
ffmpegto create a new file with the desired PIDs in place of the original ones:
ffmpeg -i ORIGINAL.ts -c copy -streamid 0:100 -streamid 1:101 NEW.ts
The above command will take strean index 0 and change the PID to 100. It will take the second stream index and change the PID to 101.
Note, these new PIDs are specified as decimal. If you run
ffprobeon the new file, you will see the PIDs specified in hex, but converting to decimal will give you the same values you entered on the previous command.