I have a ".ts" file. It is the baseband frame of a DVBS signal which have been recorded. It has some Programs and streams. I use FFmpeg to reconstruct the streams. When I use FFmpeg, this context is shown which contains service_name. How I can export a list of Programs (Not streams) and 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)
Can I do it by using ffmpeg-python? Is there any direct command in FFmpeg to show these tags or, I have to write a code to analyze "cmd JSON log"?
The equivalent ffmpeg-python command to llogan's answer is:
p = ffmpeg.probe('input.ts', show_entries='program=program_id:program_tags=service_name')
The result is a dictionary that may contain lists and sub-dictionaries.
Note: It looks like ffmpeg.probe
returns more information than we are asking for, but we can simply ignore it.
Here is a Python code sample for getting the service names (using 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)
Output:
program_id 1 has Service Name: Service01