[FFmpeg-devel] [PATCH] examples/vaapi_enc: Add a VAAPI encoding example.

Jun Zhao mypopydev at gmail.com
Mon Jul 31 05:09:29 EEST 2017



On 2017/7/30 18:45, Moritz Barsnick wrote:
> On Fri, Jul 28, 2017 at 14:01:37 +0800, Jun Zhao wrote:
> 
> It doesn't really matter much functionally, but I consider it good
> style to report errors properly, especially in an example which will be
> used by othe> 
>> +    fin = fopen(input_file, "r");
>> +    fout = fopen(output_file, "w+b");
>> +    if (!fin || !fout) {
>> +        fprintf(stderr, "Fail to open input or output file.\n");
> 
> Here, one would evaluate errno on each fopen(), e.g. with perror() or
> whatever ffmpeg's equivalent is.> 
>> +    ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI,
>> +                                 NULL, NULL, 0);
>> +    if (ret < 0) {
>> +        fprintf(stderr, "Failed to create a VAAPI device.\n");
> 
> The AVERROR return code should be reported to the user, e.g. by the use
> of av_err2str(ret) (see other examples).
> 
>> +    if (!(codec = avcodec_find_encoder_by_name(enc_name))) {
>> +        fprintf(stderr, "Could not find encoder.\n");
> 
>> +    if ((ret = init_filter(filter_ctx, args, hw_device_ctx)) < 0) {
>> +        fprintf(stderr, "Failed to initialize the filtering context.\n");
> 
>> +    if ((ret = avcodec_open2(avctx, codec, NULL)) < 0)
>> +        fprintf(stderr, "Cannot open video encoder codec.\n");
> 
>> +        ret = av_buffersrc_add_frame_flags(filter_ctx->buffersrc_ctx,
>> +                                           sw_frame, 0);
>> +        if (ret < 0) {
>> +            fprintf(stderr, "Error while feeding the filtergraph.\n");
> 
> Probably the same for all the above.
> 

Agree the all :)

Thanks for the coding style suggestion, will give a enhancement for error 
handle in next version.

> Cheers,
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 


More information about the ffmpeg-devel mailing list