ffmpeg_sidecar::log_parser

Function try_parse_stream

Source
pub fn try_parse_stream(string: &str) -> Option<Stream>
Expand description

Parses a line that represents a stream.

§Examples

§Video

§Input stream
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #0:0: Video: wrapped_avframe, rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "wrapped_avframe");
assert!(stream.language == "");
assert!(stream.parent_index == 0);
assert!(stream.stream_index == 0);
assert!(stream.is_video());
let video_data = stream.video_data().unwrap();
assert!(video_data.pix_fmt == "rgb24");
assert!(video_data.width == 320);
assert!(video_data.height == 240);
assert!(video_data.fps == 25.0);
§Output stream
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #1:5(eng): Video: h264 (avc1 / 0x31637661), yuv444p(tv, progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 12800 tbn\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "h264");
assert!(stream.language == "eng");
assert!(stream.parent_index == 1);
assert!(stream.stream_index == 5);
assert!(stream.is_video());
let video_data = stream.video_data().unwrap();
assert!(video_data.pix_fmt == "yuv444p");
assert!(video_data.width == 320);
assert!(video_data.height == 240);
assert!(video_data.fps == 25.0);

§Audio

§Input Stream
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "opus");
assert!(stream.language == "eng");
assert!(stream.parent_index == 0);
assert!(stream.stream_index == 1);
assert!(stream.is_audio());
let audio_data = stream.audio_data().unwrap();
assert!(audio_data.sample_rate == 48000);
assert!(audio_data.channels == "stereo");
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #3:10(ger): Audio: dts (DTS-HD MA), 48000 Hz, 7.1, s32p (24 bit)\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "dts");
assert!(stream.language == "ger");
assert!(stream.parent_index == 3);
assert!(stream.stream_index == 10);
assert!(stream.is_audio());
let audio_data = stream.audio_data().unwrap();
assert!(audio_data.sample_rate == 48000);
assert!(audio_data.channels == "7.1");

§Output stream

use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #10:1: Audio: mp2, 44100 Hz, mono, s16, 384 kb/s\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "mp2");
assert!(stream.language == "");
assert!(stream.parent_index == 10);
assert!(stream.stream_index == 1);
assert!(stream.is_audio());
let audio_data = stream.audio_data().unwrap();
assert!(audio_data.sample_rate == 44100);
assert!(audio_data.channels == "mono");

§Subtitle

§Input Stream
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #0:4(eng): Subtitle: ass (default) (forced)\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "ass");
assert!(stream.language == "eng");
assert!(stream.parent_index == 0);
assert!(stream.stream_index == 4);
assert!(stream.is_subtitle());
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #0:13(dut): Subtitle: hdmv_pgs_subtitle, 1920x1080\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "hdmv_pgs_subtitle");
assert!(stream.language == "dut");
assert!(stream.parent_index == 0);
assert!(stream.stream_index == 13);
assert!(stream.is_subtitle());

§Other

§Input Stream
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #0:2(und): Data: none (rtp  / 0x20707472), 53 kb/s (default)\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "none");
assert!(stream.language == "und");
assert!(stream.parent_index == 0);
assert!(stream.stream_index == 2);
assert!(stream.is_other());
use ffmpeg_sidecar::log_parser::try_parse_stream;
let line = "[info]   Stream #0:2[0x3](eng): Data: bin_data (text / 0x74786574)\n";
let stream = try_parse_stream(line).unwrap();
assert!(stream.format == "bin_data");
assert!(stream.language == "eng");
assert!(stream.parent_index == 0);
assert!(stream.stream_index == 2);
assert!(stream.is_other());