Skip to content

Instantly share code, notes, and snippets.

@vade
Created April 27, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vade/a48d2445262a3e94a51bfc12424c55ca to your computer and use it in GitHub Desktop.
Save vade/a48d2445262a3e94a51bfc12424c55ca to your computer and use it in GitHub Desktop.
while(av_read_frame(inputFormatContext, &avPacket) >= 0)
{
// Decode Video
if( videoStreamIndex == avPacket.stream_index)
{
int result = decodeVideo(inputVideoDecoderContext, videoFrame, &videoFrameCount, avPacket);
if(result > 0)
{
// retime our frame ?
if (videoFrame->pts != AV_NOPTS_VALUE)
videoFrame->pts = av_rescale_q(avPacket.pts, outputVideoStream->codec->time_base, outputVideoStream->time_base);
AVPacket encodedPacket;// (AVPacket*)malloc(sizeof(AVPacket));
av_init_packet(&encodedPacket);
encodedPacket.data = NULL;
encodedPacket.size = 0;
result = encodeVideo(outputVideoStream->codec, &encodedPacket, videoFrame);
if(result > 0)
{
int write_ret = av_interleaved_write_frame(outputFormatContext, &encodedPacket);
if (write_ret < 0)
{
fprintf(stderr, "Error writing frame\n");
}
}
}
}
// Decode Audio
else if(audioStreamIndex == avPacket.stream_index)
{
decodeAudio(inputAudioDecoderContext, audioFrame, &audioFrameCount, avPacket);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment