如何通过 ffmpeg-python 获取 service_name 和程序列表
How can I get service_name and program list by ffmpeg-python
我有一个“.ts”文件。它是已记录的 DVBS 信号的基带帧。
它有一些程序和流。
我使用 FFmpeg 重建流。当我使用 FFmpeg 时,显示的上下文包含 service_name。如何导出程序列表(不是流)和 service_names?
ffmpeg.exe -i '.\log_dvbs.ts'
Input #0, mpegts, from '.\log_dvbs.ts':
Duration: 00:01:14.30, start: 13790.701111, bitrate: 37863 kb/s
Program 301
Metadata:
service_name : IRIB TV1
service_provider: IRIB
Stream #0:23[0xbc2]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Side data:
cpb: bitrate max/min/avg: 15000000/0/0 buffer size: 1835008 vbv_delay: N/A
Stream #0:25[0xbc3]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
Program 351
Metadata:
service_name : RADIO IRAN
service_provider: IRIB
Stream #0:24[0xdb6]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
Program 302
Metadata:
service_name : IRIB TV2
service_provider:
Stream #0:15[0xbcc]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Side data:
cpb: bitrate max/min/avg: 15000000/0/0 buffer size: 1835008 vbv_delay: N/A
Stream #0:16[0xbcd]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
Program 352
Metadata:
service_name : RADIO PAYAM
service_provider: IRIB
Stream #0:1[0xdc0]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Program 303
Metadata:
service_name : IRIB TV3
service_provider: IRIB
Stream #0:11[0xbd6]: Video: mpeg2video ([2][0][0][0] / 0x0002), none, 90k tbr, 90k tbn
Stream #0:12[0xbd7]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels
Stream #0:13[0xbdb]: Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
我可以使用 ffmpeg-python 来实现吗? FFmpeg中是否有任何直接命令来显示这些标签,或者我必须编写代码来分析“cmd JSON log”?
使用ffprobe
:
ffprobe -v error -show_entries program=program_id:program_tags=service_name -of xml input.ts
示例输出:
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
<programs>
<program program_id="312">
<tag key="service_name" value="IRANdio"/>
<streams>
<stream >
<side_data_list>
<side_data />
</side_data_list>
</stream>
<stream />
</streams>
</program>
<program program_id="326">
<tag key="service_name" value="KHOY TV"/>
<streams>
<stream >
<side_data_list>
<side_data />
</side_data_list>
</stream>
<stream />
</streams>
</program>
</programs>
</ffprobe>
与 llogan 的回答等效的 ffmpeg-python 命令是:
p = ffmpeg.probe('input.ts', show_entries='program=program_id:program_tags=service_name')
结果是一个可能包含列表和子词典的字典。
注意:看起来 ffmpeg.probe
returns 的信息比我们要求的多,但我们可以简单地忽略它。
这是获取服务名称的 Python 代码示例(使用 ffmpeg-python):
import ffmpeg
# The following command from is from llogan's answer to this question.
# ffprobe -v error -show_entries program=program_id:program_tags=service_name -of xml input.ts
# Return a dictionary (The dictionary has 3 entries p['format'], p['programs'] and p['streams']).
p = ffmpeg.probe('input.ts', show_entries='program=program_id:program_tags=service_name')
programs = p['programs'] # Get p['programs']. programs is a list
# Iterate programs.
# program is a dictionary (entries are program['program_id'], program['streams'], program['tags'])
for program in programs:
tags = program['tags'] # tags is a dictionary (has the entry tags['service_name']).
service_name = tags['service_name']
print('program_id ' + str(program['program_id']) + ' has Service Name: ' + service_name)
输出:
program_id 1 has Service Name: Service01
我有一个“.ts”文件。它是已记录的 DVBS 信号的基带帧。 它有一些程序和流。 我使用 FFmpeg 重建流。当我使用 FFmpeg 时,显示的上下文包含 service_name。如何导出程序列表(不是流)和 service_names? ffmpeg.exe -i '.\log_dvbs.ts'
Input #0, mpegts, from '.\log_dvbs.ts':
Duration: 00:01:14.30, start: 13790.701111, bitrate: 37863 kb/s
Program 301
Metadata:
service_name : IRIB TV1
service_provider: IRIB
Stream #0:23[0xbc2]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Side data:
cpb: bitrate max/min/avg: 15000000/0/0 buffer size: 1835008 vbv_delay: N/A
Stream #0:25[0xbc3]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
Program 351
Metadata:
service_name : RADIO IRAN
service_provider: IRIB
Stream #0:24[0xdb6]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
Program 302
Metadata:
service_name : IRIB TV2
service_provider:
Stream #0:15[0xbcc]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Side data:
cpb: bitrate max/min/avg: 15000000/0/0 buffer size: 1835008 vbv_delay: N/A
Stream #0:16[0xbcd]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
Program 352
Metadata:
service_name : RADIO PAYAM
service_provider: IRIB
Stream #0:1[0xdc0]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 192 kb/s
Program 303
Metadata:
service_name : IRIB TV3
service_provider: IRIB
Stream #0:11[0xbd6]: Video: mpeg2video ([2][0][0][0] / 0x0002), none, 90k tbr, 90k tbn
Stream #0:12[0xbd7]: Audio: mp3 ([3][0][0][0] / 0x0003), 0 channels
Stream #0:13[0xbdb]: Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
我可以使用 ffmpeg-python 来实现吗? FFmpeg中是否有任何直接命令来显示这些标签,或者我必须编写代码来分析“cmd JSON log”?
使用ffprobe
:
ffprobe -v error -show_entries program=program_id:program_tags=service_name -of xml input.ts
示例输出:
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
<programs>
<program program_id="312">
<tag key="service_name" value="IRANdio"/>
<streams>
<stream >
<side_data_list>
<side_data />
</side_data_list>
</stream>
<stream />
</streams>
</program>
<program program_id="326">
<tag key="service_name" value="KHOY TV"/>
<streams>
<stream >
<side_data_list>
<side_data />
</side_data_list>
</stream>
<stream />
</streams>
</program>
</programs>
</ffprobe>
与 llogan 的回答等效的 ffmpeg-python 命令是:
p = ffmpeg.probe('input.ts', show_entries='program=program_id:program_tags=service_name')
结果是一个可能包含列表和子词典的字典。
注意:看起来 ffmpeg.probe
returns 的信息比我们要求的多,但我们可以简单地忽略它。
这是获取服务名称的 Python 代码示例(使用 ffmpeg-python):
import ffmpeg
# The following command from is from llogan's answer to this question.
# ffprobe -v error -show_entries program=program_id:program_tags=service_name -of xml input.ts
# Return a dictionary (The dictionary has 3 entries p['format'], p['programs'] and p['streams']).
p = ffmpeg.probe('input.ts', show_entries='program=program_id:program_tags=service_name')
programs = p['programs'] # Get p['programs']. programs is a list
# Iterate programs.
# program is a dictionary (entries are program['program_id'], program['streams'], program['tags'])
for program in programs:
tags = program['tags'] # tags is a dictionary (has the entry tags['service_name']).
service_name = tags['service_name']
print('program_id ' + str(program['program_id']) + ' has Service Name: ' + service_name)
输出:
program_id 1 has Service Name: Service01