c# - 在带有图文电视字幕的文件上使用 ffprobe 时程序挂起

标签 c# ffmpeg ffprobe

在包含图文电视字幕的 MKV 文件上运行 ffprobe 时出现问题。代码位于 C# 库中,适用于其他 MKV 文件。

运行最新的:

ffprobe -v

ffprobe version N-42347-g299387e Copyright (c) 2007-2012 the FFmpeg developers
  built on Jul  8 2012 15:44:54 with gcc 4.7.1

代码:

string args = string.Format("-show_format -show_streams \"{0}\"", FileName);

Process p = new Process();
p.StartInfo = new ProcessStartInfo(FFPROBE_PATH);
p.StartInfo.Arguments = args;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WorkingDirectory = System.IO.Directory.GetCurrentDirectory();
p.Start();

while (!p.HasExited)
{
    System.Threading.Thread.Sleep(100);
}

string output = p.StandardOutput.ReadToEnd().Replace("\r\n", "\n");

文件名具有 UNC 路径 - 尝试使用 FileName 参数但出现错误,因此通过参数传递文件名。

如果我运行以下命令行:

ffprobe -show_format -show_streams "\\192.168.10.1\content\Breakfast At Tiffany's sample preview.mkv"

我得到以下输出(注意错误 - “ID 不支持的编解码器...”):

ffprobe -show_format -show_streams "\\192.168.10.1\content\Breakfast At Tiffany's sample preview.mkv"

ffprobe version N-42347-g299387e Copyright (c) 2007-2012 the FFmpeg developers
  built on Jul  8 2012 15:44:54 with gcc 4.7.1
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-fr
ei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-li
bmp3lame --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutv
ideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --e
nable-zlib
  libavutil      51. 64.100 / 51. 64.100
  libavcodec     54. 33.100 / 54. 33.100
  libavformat    54. 15.102 / 54. 15.102
  libavdevice    54.  1.100 / 54.  1.100
  libavfilter     3.  1.100 /  3.  1.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, matroska,webm, from 'c:\dev\content\Breakfast At Tiffany's sample preview.mkv':
  Metadata:
    creation_time   : 2011-12-14 21:27:01
  Duration: 00:01:02.77, start: 0.000000, bitrate: 4071 kb/s
    Stream #0:0: Video: h264 (High), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Metadata:
      title           : x264   1920x1080   Bitrate=4776 kbps   AvQuant=21.406   Rip by ShivaShanti
    Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), s16, 448 kb/s (default)
    Metadata:
      title           : English Ac3 5.1 chnls 448 kbps
    Stream #0:2(ita): Audio: ac3, 48000 Hz, stereo, s16, 224 kb/s
    Metadata:
      title           : Italian Ac3 2.0 chnls 224  kbps
    Stream #0:3(eng): Subtitle: text (default)
    Metadata:
      title           : english
    Stream #0:4(ita): Subtitle: text
    Metadata:
      title           : italian
    Stream #0:5(dan): Subtitle: text
    Metadata:
      title           : danish
    Stream #0:6(dut): Subtitle: text
    Metadata:
      title           : dutch
    Stream #0:7(fin): Subtitle: text
    Metadata:
      title           : finnish
    Stream #0:8(fre): Subtitle: text
    Metadata:
      title           : french
    Stream #0:9(ger): Subtitle: text
    Metadata:
      title           : german
    Stream #0:10(nor): Subtitle: text
    Metadata:
      title           : norwegian
    Stream #0:11(spa): Subtitle: text
    Metadata:
      title           : spanish
    Stream #0:12(swe): Subtitle: text
    Metadata:
      title           : swedish
    Stream #0:13(eng): Subtitle: text
    Metadata:
      title           : english hearig impaired
Unsupported codec with id 94210 for input stream 3
Unsupported codec with id 94210 for input stream 4
Unsupported codec with id 94210 for input stream 5
Unsupported codec with id 94210 for input stream 6
Unsupported codec with id 94210 for input stream 7
Unsupported codec with id 94210 for input stream 8
Unsupported codec with id 94210 for input stream 9
Unsupported codec with id 94210 for input stream 10
Unsupported codec with id 94210 for input stream 11
Unsupported codec with id 94210 for input stream 12
Unsupported codec with id 94210 for input stream 13
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1920
height=1080
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=41
timecode=N/A
is_avc=1
nal_length_size=4
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:title=x264   1920x1080   Bitrate=4776 kbps   AvQuant=21.406   Rip by ShivaShanti
[/STREAM]
[STREAM]
index=1
codec_name=ac3
codec_long_name=ATSC A/52A (AC-3)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=s16
sample_rate=48000
channels=6
bits_per_sample=0
dmix_mode=-1
ltrt_cmixlev=-1.000000
ltrt_surmixlev=-1.000000
loro_cmixlev=-1.000000
loro_surmixlev=-1.000000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=448000
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=eng
TAG:title=English Ac3 5.1 chnls 448 kbps
[/STREAM]
[STREAM]
index=2
codec_name=ac3
codec_long_name=ATSC A/52A (AC-3)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=s16
sample_rate=48000
channels=2
bits_per_sample=0
dmix_mode=-1
ltrt_cmixlev=-1.000000
ltrt_surmixlev=-1.000000
loro_cmixlev=-1.000000
loro_surmixlev=-1.000000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=224000
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=ita
TAG:title=Italian Ac3 2.0 chnls 224  kbps
[/STREAM]
[STREAM]
index=3
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=eng
TAG:title=english
[/STREAM]
[STREAM]
index=4
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=ita
TAG:title=italian
[/STREAM]
[STREAM]
index=5
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=dan
TAG:title=danish
[/STREAM]
[STREAM]
index=6
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=dut
TAG:title=dutch
[/STREAM]
[STREAM]
index=7
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=fin
TAG:title=finnish
[/STREAM]
[STREAM]
index=8
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=fre
TAG:title=french
[/STREAM]
[STREAM]
index=9
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=ger
TAG:title=german
[/STREAM]
[STREAM]
index=10
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=nor
TAG:title=norwegian
[/STREAM]
[STREAM]
index=11
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=spa
TAG:title=spanish
[/STREAM]
[STREAM]
index=12
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=swe
TAG:title=swedish
[/STREAM]
[STREAM]
index=13
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=subtitle
codec_time_base=1/1000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_time=0.000000
duration=N/A
bit_rate=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
TAG:language=eng
TAG:title=english hearig impaired
[/STREAM]
[FORMAT]
filename=c:\dev\content\Breakfast At Tiffany's sample preview.mkv
nb_streams=14
format_name=matroska,webm
format_long_name=Matroska/WebM file format
start_time=0.000000
duration=62.776000
size=31947628
bit_rate=4071317
TAG:creation_time=2011-12-14 21:27:01
[/FORMAT]

我的问题是,该进程似乎挂起。我拿出“CreateNoWindow”选项,当然,我在屏幕上看到一个大的空白窗口,通常只是在普通文件上闪烁。然而,对于图文电视字幕文件,它仍然存在。如果我手动关闭它,程序会继续,并且我似乎得到了我想要的输出。

所以我的问题是,如何进一步调试它,找出挂起的原因以及如何处理错误(或简单地忽略它)并继续?

最佳答案

啊,找到了another article这回答了我的问题。看来我一定陷入了僵局。现在工作正常!

修改后的代码:

string args = string.Format("-show_format -show_streams \"{0}\"", FileName);

Process p = new Process();
p.StartInfo = new ProcessStartInfo(FFPROBE_PATH);
p.StartInfo.Arguments = args;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WorkingDirectory = System.IO.Directory.GetCurrentDirectory();
p.Start();

string output = p.StandardOutput.ReadToEnd().Replace("\r\n", "\n");
p.WaitForExit();

关于c# - 在带有图文电视字幕的文件上使用 ffprobe 时程序挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11439810/

相关文章:

c# - 仅当使用 unity DI 回收应用程序池时,webapi 调用才会失败

c# - 中止对非托管 DLL 的调用

video - 使用 ffprobe 检查文件是仅音频还是视频

bash - ffmpeg/bash - 多个输出的映射代码

android - 使用参数 'pan' 初始化过滤器 'stereo:c0<c0+c2:c1<c1+c3' 时出错

video - 如何为 mp4 容器的视频流指定偏移量和查找位置?

c# - 使用 RX 跟踪可观察集合中的多个项目

c# - Blazor:每次 for 循环旋转时组件不会更新

python - 使用 ffmpeg/ffprobe 的 CMD 错误输出子进程

php ffmpeg 获取视频时长