Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad error message from VideoWriter::open() about unknown fourcc #12471

Open
duanegi opened this issue Sep 8, 2018 · 2 comments
Open

Bad error message from VideoWriter::open() about unknown fourcc #12471

duanegi opened this issue Sep 8, 2018 · 2 comments

Comments

@duanegi
Copy link

duanegi commented Sep 8, 2018

System information (version)
  • OpenCV => 3.4.0
  • Operating System / Platform => all
  • Compiler => all
Detailed description

When one runs the following code:

fourcc = cv2.VideoWriter_fourcc(*'PIM1')
out = cv2.VideoWriter('output.mpeg',fourcc, 20.0, (640,480))

The code complains about an invalid fourcc value, but still runs correctly.

Steps to reproduce

The problem seems to be in cap_ffmpeg_impl.hpp ( CvVideoWrite_FFMPEG::open )

This code first uses the file extension (av_guess_format) to find an appropriate list of fourcc's to check for. If it does not find the fourcc in this list, it then uses a default list of fourcc's ( avformat_get_mov_video_tags). The fourcc checks are using av_codec_get_id().

After if finds a fourcc match, it then validates that the fourcc is in the original list from the file extension, and prints an error message if this is the case. When the fourcc is from the default list, it does not match the original list, so an error message is always printed in this case. The error message is just informational and does not change the program flow.

There seems to be two solutions:
(1) remove the final valid step (not sure why needed)
(2) validate against the default list when use default list (this seems to be the easier of the two)

The change for (2) is quite small:

diff modules/videoio/src/cap_ffmpeg_impl.hpp  hold/
1930d1929
<     const AVCodecTag *const *chk_tags = fmt->codec_tag;
1961,1963c1960
<         }else{
< 	  chk_tags = fallback_tags;
< 	}
---
>         }
1966c1963
<     if (cv_ff_codec_tag_list_match(chk_tags, codec_id, fourcc) == false)
---
>     if (cv_ff_codec_tag_list_match(fmt->codec_tag, codec_id, fourcc) == false)
@alalek
Copy link
Member

alalek commented Sep 8, 2018

  1. Video containers support subset of codecs only. Exactly this message says if something strange is going here. I have no idea how it works in your case, but I don't see any problem here with this message.
  2. OpenCV "fourcc"-based FFMPEG codec selection is not well designed initially (single "fourcc" is not enough to select codec / frame format / etc). But current alternative - using FFmpeg directly.
  3. This is needed for supporting MKV / H264 VideoWriter.

@duanegi
Copy link
Author

duanegi commented Sep 8, 2018

The message really means "matched the codec/fourcc pair from the fallback list rather than the list associated with the file extension" ... not really sure why such a message needs to be printed to stderr

The current message "OpenCV:: FFMPEG: tag 0x%0dx/'%c%c%c%c%c' is not supported with codec id %d and format %s/%x\n" really does not seem to indicate correctly was is going on...

This issue can up because the .avi based mpeg1 encoder does not support file concatenation; whereas, the fallback mpeg1 decoder does correctly support this. Hence, for mpeg1, one is forced to live with this error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants