如何通过Python从DPX文件读取时间码

2024-05-16 20:02:58 发布

您现在位置:Python中文网/ 问答频道 /正文

作为更大脚本的一部分,我需要能够读取DPX文件的时间码。我有ffmpeg和ffprobe,但我是一个初学者,当谈到使用这些程序。你知道吗

对于MOV文件,我可以拼凑起来:

def GetStartingTimecodeFromMOV(Filename):
    cmd = "ffprobe -v quiet -print_format json -show_streams -show_format"
    args = shlex.split(cmd)
    args.append(Filename)
    String = subprocess.check_output(args).decode('utf-8')
    for Line in String.split("\n"):
        if Line.count("timecode"):
            Timecode = Line.split("\"")[3]
            return Timecode

…但它们的元数据在MOV文件和DPX之间肯定有细微的差别。任何帮助都将不胜感激。你知道吗

如果我尝试。。。。你知道吗

ffprobe -v quiet -show_streams -show_format "/Render/MyFile/MyFile.0001016.dpx"

…然后我得到了很多有用的信息,包括分辨率和FPS,但没有时间码(至少对于DPX文件)

[STREAM]
index=0
codec_name=dpx
codec_long_name=DPX (Digital Picture Exchange) image
profile=unknown
codec_type=video
codec_time_base=0/1
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1920
height=1600
coded_width=1920
coded_height=1600
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=6:5
pix_fmt=rgb48be
level=-99
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=unspecified
field_order=unknown
timecode=N/A
refs=1
id=N/A
r_frame_rate=25/1
avg_frame_rate=0/0
time_base=1/25
start_pts=N/A
start_time=N/A
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=16
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]
[FORMAT]
filename=/Render/MyFile/MyFile.0001016.dpx
nb_streams=1
nb_programs=0
format_name=dpx_pipe
format_long_name=piped dpx sequence
start_time=N/A
duration=N/A
size=18440192
bit_rate=N/A
probe_score=51
[/FORMAT]

Tags: 文件nameformatratetimeshowunknownstreams