leandromoreira / ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: πŸ‡ΊπŸ‡Έ πŸ‡¨πŸ‡³ πŸ‡°πŸ‡· πŸ‡ͺπŸ‡Έ πŸ‡»πŸ‡³ πŸ‡§πŸ‡·
https://github.com/leandromoreira/ffmpeg-libav-tutorial
BSD 3-Clause "New" or "Revised" License
9.82k stars 941 forks source link

Change pCodecParameters to pLocalCodecParameters in README.md #37

Open Page-David opened 5 years ago

Page-David commented 5 years ago

Hi, I noticed this line of code in README.md

printf("\tCodec %s ID %d bit_rate %lld", pLocalCodec->long_name, pLocalCodec->id, pCodecParameters->bit_rate);

in which pLocalCodec is not declared in the article before used which might cause confusion in my view. Digging into the c code, I found this line.

https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/cdd616ce871078ebb67601af207f10a299914e19/0_hello_world.c#L110

As for a guess, maybe the author firstly write the c code and copy-and-paste these important parts into README and lead to this issue. By the way, I think adding \n afterward printfs could make output looks better. Hope that useful.

UPDATE This line of code has the same problem:

AVCodecContext *pCodecContext = avcodec_alloc_context3(pCodec);

Maybe it will be better to replace pCodec with pLocalCodec.

leandromoreira commented 5 years ago

Good catch.

Page-David commented 5 years ago

Hi, it is now that I finally find that simply replacing pLocalCodec with pLocalCodecParameters might not be a perfect solution. Instead, it might be better to firstly state that when we do the while loop to read AVPacket we need to distinguish video track from sound track. Also, when we create pCodecContext and call avcodec_parameters_to_context, we must use AVCodec and AVCodecParameters from the video track. Thus we need to "remember" them with pCodec etc. What do you think about?

Btw, could you please explain why do we need avformat_alloc_context() for *pFormatContext and why do we need av_frame_unref(pFrame);? So far, assigning NULL to *pFormatContext or remove av_frame_unref did not cause any problem for me. In chapter 2, AVFormatContext was assigned like AVFormatContext *input_format_context = NULL; why this time not avformat_alloc_context()?