You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey , I am trying to decode a video and encode it back into a video file, but it is not working as expected. Please help me to resolve the errors or provide some insights where I'm doing wrong.
Here are my code files:
Extract_frames:use crate::decoder::decode_packet;
use crate::encoder::flush_encoder;
use rsmpeg::avcodec::{AVCodec, AVCodecContext};
use rsmpeg::avformat::{AVFormatContextInput, AVFormatContextOutput};
use rsmpeg::avutil::av_inv_q;
use rsmpeg::ffi::{self};
use std::error::Error;
use std::ffi::CString;
}
Decoder:use crate::encoder::encode_frame;
use crate::yuv_to_rgb::yuv_rgb_sws; // Assume you have this conversion function defined
use rsmpeg::avcodec::{AVCodecContext, AVPacket};
use rsmpeg::avformat::AVFormatContextOutput;
use rsmpeg::avutil::av_rescale_q;
use rsmpeg::ffi::AV_PICTURE_TYPE_NONE;
use std::error::Error;
output_codec_ctx: &mut AVCodecContext,
output_ctx: &mut AVFormatContextOutput,
total_decoded: &mut usize, // Add parameter for total decoded frames
total_encoded: &mut usize,
) -> Result<(), Box> {
// Send the packet to the decoder
if input_codec_ctx.send_packet(Some(pkt)).is_err() {
return Err("Failed to send packet to decoder".into());
}
while let Ok(mut frame) = input_codec_ctx.receive_frame() {
frame.set_pts(frame.best_effort_timestamp);
frame.set_pict_type(AV_PICTURE_TYPE_NONE);
if frame.pts != rsmpeg::ffi::AV_NOPTS_VALUE {
frame.set_pts(av_rescale_q(frame.pts, frame.time_base, output_codec_ctx.time_base));
}
// Convert YUV frame to RGB (if needed)
// let rgb_frame = yuv_rgb_sws(&frame);
// let mut yuv_frame = crate::yuv_to_rgb::rgb_yuv_sws(&rgb_frame);
// yuv_frame.set_pts(frame.pts);
*total_decoded+=1;
// Encode the frame
encode_frame(output_codec_ctx, output_ctx, Some(&frame), stream_index)?;
*total_encoded+=1;
}
Ok(())
}
Encoder:use anyhow::Context;
use rsmpeg::avcodec::AVCodecContext;
use rsmpeg::avformat::AVFormatContextOutput;
use rsmpeg::avutil:: AVFrame;
use std::error::Error;
Hey , I am trying to decode a video and encode it back into a video file, but it is not working as expected. Please help me to resolve the errors or provide some insights where I'm doing wrong.
Here are my code files:
Extract_frames:use crate::decoder::decode_packet;
use crate::encoder::flush_encoder;
use rsmpeg::avcodec::{AVCodec, AVCodecContext};
use rsmpeg::avformat::{AVFormatContextInput, AVFormatContextOutput};
use rsmpeg::avutil::av_inv_q;
use rsmpeg::ffi::{self};
use std::error::Error;
use std::ffi::CString;
pub fn extract_frames(video_path: &str, total_decoded: &mut usize, total_encoded: &mut usize) -> Result<(), Box> {
let mut input_format_context =
AVFormatContextInput::open(&CString::new(video_path)?, None, &mut None)?;
{
let mut stream = output_format_ctx.new_stream();
stream.set_codecpar(output_codec_ctx.extract_codecpar());
stream.set_time_base(output_codec_ctx.time_base);
}
output_format_ctx.write_header(&mut None)?;
}
Decoder:use crate::encoder::encode_frame;
use crate::yuv_to_rgb::yuv_rgb_sws; // Assume you have this conversion function defined
use rsmpeg::avcodec::{AVCodecContext, AVPacket};
use rsmpeg::avformat::AVFormatContextOutput;
use rsmpeg::avutil::av_rescale_q;
use rsmpeg::ffi::AV_PICTURE_TYPE_NONE;
use std::error::Error;
pub fn decode_packet(
input_codec_ctx: &mut AVCodecContext,
pkt: &AVPacket,
stream_index: i32,
) -> Result<(), Box> {
}
Encoder:use anyhow::Context;
use rsmpeg::avcodec::AVCodecContext;
use rsmpeg::avformat::AVFormatContextOutput;
use rsmpeg::avutil:: AVFrame;
use std::error::Error;
pub fn encode_frame(
output_codec_ctx: &mut AVCodecContext,
output_ctx: &mut AVFormatContextOutput,
frame: Option<&AVFrame>,
stream_index:i32
) -> Result<(), Box> {
}
pub fn flush_encoder(
output_codec_ctx: &mut AVCodecContext,
output_format_ctx: &mut AVFormatContextOutput,
stream_index:i32
) -> Result<(), Box> {
}
Now I am getting this error : [libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] non-strictly-monotonic PTS
[libx264 @ 0x55c07dfca240] frame I:1 Avg QP:26.14 size: 34194
[libx264 @ 0x55c07dfca240] mb I I16..4: 33.0% 59.5% 7.5%
[libx264 @ 0x55c07dfca240] 8x8 transform intra:59.5%
[libx264 @ 0x55c07dfca240] coded y,uvDC,uvAC intra: 23.7% 34.4% 6.2%
[libx264 @ 0x55c07dfca240] i16 v,h,dc,p: 42% 32% 6% 20%
[libx264 @ 0x55c07dfca240] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 21% 18% 3% 4% 4% 4% 4% 3%
[libx264 @ 0x55c07dfca240] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 50% 21% 6% 3% 4% 7% 3% 5% 2%
[libx264 @ 0x55c07dfca240] i8c dc,h,v,p: 55% 19% 22% 4%
[libx264 @ 0x55c07dfca240] kb/s:inf
The text was updated successfully, but these errors were encountered: