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

How to read the timecode from a DPX file via 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]

如果您仍在寻找这个...请使用 ImageMagick (imagemagick.org)

DPX header 是标准的 SMPTE,您可以通过以下方式获取它:

magick identify -format "%[dpx:television.time.code]" 76890.dpx

在这种情况下,它返回值: 01:00:21:16