Commit 1532889e authored by Xu Guangxin's avatar Xu Guangxin Committed by Luca Barbato
Browse files

muxer: set key frame flag for container format

container format will use this information to build seek index.
This will make the mp4 seekable
parent d3992e51
......@@ -10,6 +10,8 @@
#[cfg(feature = "avformat-sys")]
use avformat_sys::*;
#[allow(unused_imports)]
use rav1e::prelude::*;
#[allow(unused_imports)]
use super::Muxer;
#[allow(unused_imports)]
......@@ -90,12 +92,15 @@ impl Muxer for AvformatMuxer {
}
}
fn write_frame(&mut self, pts: u64, data: &[u8]) {
fn write_frame(&mut self, pts: u64, data: &[u8], frame_type: FrameType) {
unsafe {
let mut pkt: AVPacket = mem::zeroed();
av_init_packet(&mut pkt);
pkt.data = data.as_ptr() as *mut _;
pkt.size = data.len() as i32;
if frame_type == FrameType::KEY {
pkt.flags = AV_PKT_FLAG_KEY as i32;
}
let pts = av_rescale_q(pts as i64, self.time_base, self.stream_time_base);
pkt.pts = pts;
......
use super::Muxer;
use ivf::*;
use rav1e::prelude::*;
use std::fs::File;
use std::io;
use std::io::Write;
......@@ -25,7 +26,7 @@ impl Muxer for IvfMuxer {
);
}
fn write_frame(&mut self, pts: u64, data: &[u8]) {
fn write_frame(&mut self, pts: u64, data: &[u8], _frame_type: FrameType) {
write_ivf_frame(&mut self.output, pts, data);
}
......
......@@ -16,6 +16,8 @@ use mp4::Mp4Muxer;
mod y4m;
pub use self::y4m::write_y4m_frame;
use rav1e::prelude::*;
#[cfg(feature = "avformat-sys")]
mod avformat;
......@@ -30,7 +32,7 @@ pub trait Muxer {
framerate_den: usize
);
fn write_frame(&mut self, pts: u64, data: &[u8]);
fn write_frame(&mut self, pts: u64, data: &[u8], frame_type: FrameType);
fn flush(&mut self) -> io::Result<()>;
}
......
......@@ -118,7 +118,7 @@ fn process_frame<T: Pixel, D: Decoder>(
let pkt_wrapped = ctx.receive_packet();
match pkt_wrapped {
Ok(pkt) => {
output_file.write_frame(pkt.input_frameno as u64, pkt.data.as_ref());
output_file.write_frame(pkt.input_frameno as u64, pkt.data.as_ref(), pkt.frame_type);
if let (Some(ref mut y4m_enc_uw), Some(ref rec)) = (y4m_enc.as_mut(), &pkt.rec) {
write_y4m_frame(y4m_enc_uw, rec, y4m_details);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment