Dealing with FFMPEG Error while opening codec for output stream…

Quick post about the ffmpeg error message: “Error while opening codec for output stream #0.0 – maybe incorrect parameters such as bit_rate, rate, width or height” .

We received some video files from a partner in the Safecity project, which did not play in all media players.
We tried VLC, windows media player, and a variety of other players but nothing worked.

Checking the file with a hex editor, I saw there was data within the video, and thought to try converting with FFMPEG using commands such as:

ffmpeg -i “damaged_file.avi” converted_file.mp4

However, ffmpeg  failed with the following error message:

Error while opening codec for output stream #0.0 – maybe incorrect parameters such as bit_rate, rate, width or height

The solution I found to fix the broken video file was the following:

1) I tried converting the file to a series of images and discovered that ffmpeg exported images successfully – I knew the file did contain actual video data:

 ffmpeg -i “damaged_file.avi”  -f image2 videoFrames%05d.png

2) I realized the problem was possibly due to the video container not containing necessary information such as resolution, framerate, etc – just a guess. Therefore I made my FFMPEG conversion command very specific by including information about framerate. bit rate, video codec, etc, and the file was successfully transcoded:

ffmpeg -i “damaged_file.avi” -crf 35.0 -vcodec libx264 -acodec libfaac -ar 48000 -ab 128k -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 repaired_file.mp4

3) Following, I tried the tool WinFF (a front-end for FFMPEG)  and used some of the pre-set profiles which was more user-friendly than converting multiple damaged files by hand through the console (or writing a BAT file).
If you have a similar experience feel free to share 🙂 !



Menelaos Bakopoulos

Mr. Menelaos Bakopoulos is currently pursuing his PhD both at Center for TeleInFrastruktur (CTiF) at Aalborg University (AAU) in Denmark and Athens Information Technology (AIT) in Athens, Greece. He received a Master in Information Technology and Telecommunications Systems from Athens Information Technology and a B.Sc. in Computer Science & Management Information Systems from the American College of Thessaloniki. Since April 2008 he has been a member of the Multimedia, Knowledge, and Web Technologies Group.

More Posts