avcodec_open and changing the encoding framerate
Hi, I'm using the lib in a project and at some point I need to transcode a video from a format/codec to another. My problem lies at the encoding stage. Following the example source provided in the source, I can encode to CODEC_ID_MPEG2VIDEO using time base of 25/1. However, as soon as I step aside from that, avcodec_open() fails. using a time base of 10/1 or 40/1 for exemple, raises -1. using CODEC_ID_MJPEG, even at 25/1, raises -1. Here is the relevant piece of code I use. Maybe I'm not setting the AVCodecContext properly ? Maybe I need to put some infos into an AVFormatContext as well ? What is stumping me is why would it work at 25/1 and not at other framerates... Any pointers would be appreciated, thanks. joan. code snippet follows ------------------------------ AVCodec* pOutputCodec; AVCodecContext* pOutputCodecContext = NULL; pOutputCodec = avcodec_find_encoder(CODEC_ID_MPEG2VIDEO); if (!pOutputCodec) break; pOutputCodecContext = avcodec_alloc_context(); // Are the following 3 needed at all ? pOutputCodecContext->codec_id = CODEC_ID_MPEG2VIDEO; pOutputCodecContext->codec_type = CODEC_TYPE_VIDEO; pOutputCodecContext->codec = pOutputCodec; pOutputCodecContext->bit_rate = 400000; pOutputCodecContext->width = 352; pOutputCodecContext->height = 288; pOutputCodecContext->time_base.den = 10; pOutputCodecContext->time_base.num = 1; pOutputCodecContext->gop_size = 0; pOutputCodecContext->max_b_frames = 1; pOutputCodecContext->pix_fmt = PIX_FMT_YUV420P; // Other infos needed ? if (avcodec_open(pOutputCodecContext, pOutputCodec) < 0) break; // Gets here. (...) joan.
On date Sunday 2007-08-19 13:30:00 +0200, joan charmant encoded:
Hi,
I'm using the lib in a project and at some point I need to transcode a video from a format/codec to another.
My problem lies at the encoding stage. Following the example source provided in the source, I can encode to CODEC_ID_MPEG2VIDEO using time base of 25/1.
However, as soon as I step aside from that, avcodec_open() fails.
using a time base of 10/1 or 40/1 for exemple, raises -1. using CODEC_ID_MJPEG, even at 25/1, raises -1.
Here is the relevant piece of code I use. Maybe I'm not setting the AVCodecContext properly ? Maybe I need to put some infos into an AVFormatContext as well ? What is stumping me is why would it work at 25/1 and not at other framerates... Any pointers would be appreciated, thanks.
http://ffmpeg.mplayerhq.hu/faq.html#SEC15 AVCodec mpeg2video_encoder = { "mpeg2video", CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, sizeof(MpegEncContext), encode_init, MPV_encode_picture, MPV_encode_end, .supported_framerates= ff_frame_rate_tab+1, ^^^^^^^^^^^^^^^^^^^ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, -1}, .capabilities= CODEC_CAP_DELAY, }; const AVRational ff_frame_rate_tab[] = { { 0, 0}, {24000, 1001}, { 24, 1}, { 25, 1}, {30000, 1001}, { 30, 1}, { 50, 1}, {60000, 1001}, { 60, 1}, // Xing's 15fps: (9) { 15, 1}, // libmpeg3's "Unofficial economy rates": (10-13) { 5, 1}, { 10, 1}, { 12, 1}, { 15, 1}, { 0, 0}, }; Hope it's more clear now. HTH, cheers. -- ffmpeg-user random tip #5 FF-mpeg documentation: http://ffmpeg.mplayerhq.hu/documentation.html
Hello, On 9/5/07, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
On date Sunday 2007-08-19 13:30:00 +0200, joan charmant encoded:
Hi,
I'm using the lib in a project and at some point I need to transcode a video from a format/codec to another.
My problem lies at the encoding stage. Following the example source provided in the source, I can encode to CODEC_ID_MPEG2VIDEO using time base of 25/1.
However, as soon as I step aside from that, avcodec_open() fails.
using a time base of 10/1 or 40/1 for exemple, raises -1. using CODEC_ID_MJPEG, even at 25/1, raises -1.
Here is the relevant piece of code I use. Maybe I'm not setting the AVCodecContext properly ? Maybe I need to put some infos into an AVFormatContext as well ? What is stumping me is why would it work at 25/1 and not at other framerates... Any pointers would be appreciated, thanks.
http://ffmpeg.mplayerhq.hu/faq.html#SEC15
AVCodec mpeg2video_encoder = { "mpeg2video", CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, sizeof(MpegEncContext), encode_init, MPV_encode_picture, MPV_encode_end, .supported_framerates= ff_frame_rate_tab+1, ^^^^^^^^^^^^^^^^^^^ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, -1}, .capabilities= CODEC_CAP_DELAY, };
const AVRational ff_frame_rate_tab[] = { { 0, 0}, {24000, 1001}, { 24, 1}, { 25, 1}, {30000, 1001}, { 30, 1}, { 50, 1}, {60000, 1001}, { 60, 1}, // Xing's 15fps: (9) { 15, 1}, // libmpeg3's "Unofficial economy rates": (10-13) { 5, 1}, { 10, 1}, { 12, 1}, { 15, 1}, { 0, 0}, };
Hope it's more clear now.
HTH, cheers.
Thank you very much for the pointer ! Sorry for the delay, I initially thought my message didn't make it to the list... joan.
participants (2)
-
jcharmant@gmail.com -
stefano.sabatini-lala@poste.it