<div dir="ltr">I'm trying to code a simple transcoder, using the new API, that replicates to the following command line:<div><br></div><div><div style="color:rgb(33,33,33);font-size:13px"><font face="monospace">ffmpeg -i input.mp4 -c:v libx264 -x264-params keyint=60:min-keyint=60:no-scenecut=1 -c:a copy output.mp4</font></div></div><div><br></div><div>I followed the transcoding example on Doxygen documentation but using the new API. </div><div><br></div><div>My attempt to code it didn't work, either I get a single audio stream on an mp4, that works, or a video stream on an mp4 that doesn't work.</div><div><br></div><div>I don't see any error message, the messages I see are these:</div><div><br></div><div><div><font face="monospace">[libx264 @ 0x7fd0ae038000] using SAR=1/1</font></div><div><font face="monospace">[libx264 @ 0x7fd0ae038000] MB rate (489600000) > level limit (2073600)</font></div><div><font face="monospace">[libx264 @ 0x7fd0ae038000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX</font></div><div><font face="monospace">[libx264 @ 0x7fd0ae038000] profile High, level 5.2</font></div></div><div><br class="inbox-inbox-Apple-interchange-newline">The whole file <a href="https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding/2_transcoding.c">https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding/2_transcoding.c</a><br></div><div><br></div><div>Anyway, what I did was: <br></div><br><b>I created a transcode context type:</b><br><br>typedef struct TrancodeContext { <br>  char *file_name; <br>  AVFormatContext *format_context; <br>  int audio_stream_index; <br>  int video_stream_index; <br>  AVStream *stream[2]; <br>  AVCodec *codec[2]; <br>  AVCodecContext *codec_context[2];<br>} TranscodeContext;<br><br><b><a href="https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding/2_transcoding.c#L120">Prepared the decoder</a> with the functions:</b><div><ol><li>avformat_alloc_context,</li><li>avformat_open_input,</li><li>avformat_find_stream_info,</li><li>avcodec_find_decoder,</li><li>avcodec_alloc_context3,</li><li>avcodec_parameters_to_context,</li><li>avcodec_open2</li></ol></div><div><b><a href="https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding/2_transcoding.c#L337">Prepared the encoder</a> with the functions:</b></div><div><ol><li>avformat_alloc_output_context2,</li><li>avformat_new_stream,</li><li>avcodec_find_encoder_by_name,</li><li>avcodec_alloc_context3,</li><li>avcodec_parameters_from_context,</li><li>avcodec_find_encoder,</li><li>avcodec_alloc_context3,</li><li>avformat_new_stream,</li><li>avcodec_open2,</li><li>avcodec_parameters_from_context,</li><li>avio_open,</li><li>avformat_write_header<br></li></ol></div><div><b>Read all the packets:</b></div><div><br><div><div>while (av_read_frame(decoder_context->format_context, input_packet) >= 0)<br></div><div><br></div><div><b><a href="https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding/2_transcoding.c#L180">Decode the video packets</a> into frames:</b></div><div><ol><li>avcodec_send_packet,</li><li>avcodec_receive_frame<br></li></ol></div><div><b><a href="https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding/2_transcoding.c#L221">Encode the frame</a> into the encoder:</b></div><div><ol><li>avcodec_send_frame,</li><li>avcodec_receive_packet,</li><li>av_packet_rescale_ts,</li><li>av_interleaved_write_frame<br></li></ol></div><div><b><a href="https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/transcoding/2_transcoding.c#L79">Copy audio stream directly</a> to the encoder:</b></div><div><ol><li>av_packet_rescale_ts,</li><li>av_interleaved_write_frame<br></li></ol></div><div><b>Finish with</b> av_write_trailer</div><div><br></div></div></div><div>Can you see anything suspicious on that? I tried really hard </div></div>