FFmpeg - 从传输流文件(.ts)中提取视频和音频

15

我希望能够通过指定PID从传输流文件(.ts)中提取某个节目的音频和视频,而不会失去质量并在生成的文件中使用相同的编解码器(输出文件为MPEG)。

使用FFmpeg是否有可能做到这一点?如果可以,我该如何操作?

我已经尝试了以下命令:

 ffmpeg -i tsfile.ts -vcodec copy -acodec copy -q:v 1 output.mpg

编辑: 请注意,已经创建了名为output.mpg的文件。该文件包含视频但是没有附加音频(无声)。另外,我无法指定程序PID来提取。

编辑2: 这里是ffmpeg -i tsfile.ts的输出结果

ffmpeg version N-47062-g26c531c Copyright (c) 2000-2012 the FFmpeg developers
built on Nov 25 2012 12:21:26 with gcc 4.7.2 (GCC)
    libavutil      52.  9.100 / 52.  9.100
    libavcodec     54. 77.100 / 54. 77.100
    libavformat    54. 37.100 / 54. 37.100
    libavdevice    54.  3.100 / 54.  3.100
    libavfilter     3. 23.102 /  3. 23.102
    libswscale      2.  1.102 /  2.  1.102
    libswresample   0. 17.101 /  0. 17.101
    libpostproc    52.  2.100 / 52.  2.100
[mpeg2video @ 0201c7a0] mpeg_decode_postinit() failure
Last message repeated 10 times
[mpegts @ 0037b800] PES packet size mismatch
Input #0, mpegts, from 'tsfile.ts':
Duration: 00:01:30.58, start: 56297.848344, bitrate: 18045 kb/s
Program 1
    Stream #0:0[0x31]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 1920x1080  [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x34]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), s16, 384      kb/s

这里是关于 .ts 文件的 tsinfo.exe 命令行工具:

Reading from C:\tsfile.ts
Scanning 10000 TS packets

Packet 1 is PAT
Program list:
    Program 1 -> PID 0020 (32)

Packet 2 is PMT with PID 0020 (32)
  Program 1, version 1, PCR PID 0031 (49)
     Program info (38 bytes): 0e 03 c0 b9 16 10 06 c0 02 71 c0 04 00 0b 02 42 3f 05 04
                              47 41 39 34 86 0d e2 65 6e 67 7e 3f ff 65 6e 67 c1 3f ff
 maximum bitrate (3 bytes): c0 b9 16
 smoothing buffer (6 bytes): c0 02 71 c0 04 00
 system clock (2 bytes): 42 3f
 Registration GA94
 Descriptor tag 86 (134) (13 bytes): e2 65 6e 67 7e 3f ff 65 6e 67 c1 3f ff
  Program streams:
PID 0031 (  49) -> Stream type 02 (  2) H.262/13818-2 video (MPEG-2) or 11172-2 constrained video
PID 0034 (  52) -> Stream type 81 (129) User private
    ES info (6 bytes): 6a 04 41 43 2d 33
    DVB AC-3 (4 bytes): 41 43 2d 33

Found 14 PAT packets and 7 PMT packets in 10000 TS packets

FFmpeg可以使用map选项和流指定符选择节目流以及节目中的基本流。 请参考-https://superuser.com/questions/343716/ffmpeg-how-to-demux-live-multi-program-transport-stream - rajneesh
如果一个TS文件包含多个节目(由DVB-T捕获的电视节目),如何拆分它?例如,我有一个包含足球+烹饪+卡通的TS文件。如何将此TS文件拆分为3个mpg文件? - Dr.jacky
3个回答

4

我可以通过提取所需流并重新混合来从ffmpeg中获得MPTS中的SPTS。我的MPTS有三个节目(一个音频、一个视频),共六个流:

ffmpeg -i mpt.ts -map 0:0 -map 0:1 -acodec copy -vcodec copy -f mpts program1.ts

1
尝试:
ffmpeg -i input.ts -map 0:0 -map 0:1 -acodec copy -vcodec copy output.ts

根据您的输入,修改地图值.ts程序。


1
尝试:
`cat *.ts | ffmpeg  -i pipe: -c:a copy -c:v copy output.mp4`

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接