我刚开始使用ffmpeg
. 我有一些 AVI 文件,我认为应该有音频,但我无法使用 VLC 播放音频。我尝试使用它ffmpeg
来分析 AVI 文件的音频。
import subprocess
def has_audio(filename):
result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
"format=nb_streams", "-of",
"default=noprint_wrappers=1:nokey=1", filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return int(result.stdout) -1
print(has_audio('filename.avi'))
下面是其中一个 AVI 文件的输出。该文件看起来有音频,但也许我错误地读取了输出。我还尝试了这个问题中的代码,它告诉我视频有音频。
如何使用任一或其他应用程序确保该文件有音频或没有音频ffmpeg
?
avi @ 0x7fddac005140] non-interleaved AVI
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'filename.avi':
Metadata:
date : 2010-06-29
Duration: 00:00:06.83, start: 0.000000, bitrate: 10607 kb/s
Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080, 9878 kb/s, 30 fps, 30 tbr, 30 tbn
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 32000 Hz, 1 channels, s16, 512 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
Metadata:
date : 2010-06-29
encoder : Lavf60.3.100
Stream #0:0: Audio: pcm_s16le, 32000 Hz, mono, s16, 512 kb/s
Metadata:
encoder : Lavc60.3.100 pcm_s16le
size=N/A time=00:00:05.99 bitrate=N/A speed=1.52e+03x
video:0kB audio:375kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_volumedetect_0 @ 0x7fdd9b704080] n_samples: 192000
[Parsed_volumedetect_0 @ 0x7fdd9b704080] mean_volume: -44.3 dB
[Parsed_volumedetect_0 @ 0x7fdd9b704080] max_volume: -16.2 dB
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_16db: 3
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_17db: 0
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_18db: 9
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_19db: 9
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_20db: 15
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_21db: 16
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_22db: 12
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_23db: 25
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_24db: 19
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_25db: 25
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_26db: 22
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_27db: 13
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_28db: 17
[Parsed_volumedetect_0 @ 0x7fdd9b704080] histogram_29db: 13
这是输出MediaInfo
Bit rate: 12884197, Frame rate: 30.000, Format: JPEG
Duration (raw value): 6833
Duration (other values:
['6 s 833 ms',
'6 s 833 ms',
'6 s 833 ms',
'00:00:06.833',
'00:00:06:25',
'00:00:06.833 (00:00:06:25)']
Track data:
{'alignment': 'Aligned',
'bit_depth': 16,
'bit_rate': 512000,
'bit_rate_mode': 'CBR',
'channel_s': 1,
'codec_id': '1',
'codec_id_url': 'http://www.microsoft.com/windows/',
'commercial_name': 'PCM',
'count': '285',
'count_of_stream_of_this_kind': '1',
'delay': 0,
'delay__origin': 'Stream',
'delay_relative_to_video': 0,
'duration': 6000,
'format': 'PCM',
'format_settings': 'Little / Signed',
'format_settings__endianness': 'Little',
'format_settings__sign': 'Signed',
'interleave__duration': 1139,
'kind_of_stream': 'Audio',
'other_alignment': ['Aligned on interleaves'],
'other_bit_depth': ['16 bits'],
'other_bit_rate': ['512 kb/s'],
'other_bit_rate_mode': ['Constant'],
'other_channel_s': ['1 channel'],
'other_delay': ['00:00:00.000', '00:00:00.000'],
'other_delay__origin': ['Raw stream'],
'other_delay_relative_to_video': ['00:00:00.000', '00:00:00.000'],
'other_duration': ['6 s 0 ms',
'6 s 0 ms',
'6 s 0 ms',
'00:00:06.000',
'00:00:06.000'],
'other_format': ['PCM'],
'other_interleave__duration': ['1139',
'1139 ms (34.17 video frames)',
'34.17'],
'other_kind_of_stream': ['Audio'],
'other_sampling_rate': ['32.0 kHz'],
'other_stream_size': ['375 KiB (4%)',
'375 KiB',
'375 KiB',
'375 KiB',
'375.0 KiB',
'375 KiB (4%)'],
'other_track_id': ['1'],
'proportion_of_this_stream': '0.04238',
'samples_count': '192000',
'sampling_rate': 32000,
'stream_identifier': '0',
'stream_size': 384000,
'streamorder': '1',
'track_id': 1,
'track_type': 'Audio'}