You are not logged in.

#1 2012-10-13 13:16:01

Army
Member
Registered: 2007-12-07
Posts: 1,784

[solved by rtfm] ffmpeg (frame dropping combining images to video)

Hi guys!

I'm currently trying to create a video out of a bunch of png files, which I created with mplayer

mplayer -vo png video.avi

and modified those images with an imagemagick script.
After that I want to combine them again with this command

ffmpeg -r 25 -i %08d.png out.mkv

It works quite well and looks amazing, BUT ffmpeg drops a lot of frames, which leads to an end-result that doesn't work for me. The video is a music video, so it's important that it's in sync with the music.


I've been searching for solutions on the web and looked into the ffmpeg manpage. In the manpage I found the -vsync switch. It seems to me that

-vsync drop

or

-vsync passthrough

is what I need, but when I add those switches to the commandline, the encoding process stops with this message

av_interleaved_write_frame(): Invalid argument=00:00:00.00 bitrate=   0.0kbits/s

Until then it looks like no frames are being dropped, so this might be a good direction. With the other -vsync switches the encoding works, but with dropped frames.


I'm a bit lost here, since I've never really worked that much with ffmpeg. But the end result is so good looking that I definitely want to finish this right. I just hope there's an ffmpeg guru here who can help me.

Last edited by Army (2012-10-14 13:42:45)

Offline

#2 2012-10-13 14:01:55

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,804
Website

Re: [solved by rtfm] ffmpeg (frame dropping combining images to video)

I can't help with you immediate issue, but I have used the ffmpeg library in my own programs before.  I learned just enough to do what I needed to do.

If practical - or particularly if you will do this type of this more than once, and you know some C - you may want to write a small program that does this all in one pipeline rather than converting the entire video to images, imagemagick each one, then reassemble into video.

With the ffmpeg library it is very easy to step through a video and do some work on each frame and write them back out to the video.  Imagemagick also has good libs, so this would make the whole process a lot more streamlined.

This could also potentially aid in troubleshooting the immediate problem as you can put in some error checking or extra verbosity to see exactly what is happening ... or potentially the problem wouldn't arise as the frames don't go through as many encoding and decoding steps in the first place.

(edit: typo)

Last edited by Trilby (2012-10-13 14:03:55)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#3 2012-10-13 15:21:18

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: [solved by rtfm] ffmpeg (frame dropping combining images to video)

Thanks for your input!

Unfortunately my coding skills aren't really worth mentioning. What you describe sounds wonderful, but right now I have no idea how to do this.

I don't intend to do this more than once, I just had the idea to make the video kind of look like it has been drawn by hand, so I looked up how to cartoonize images. The method works quite fine, except of those frame drops.

Later today I'll show my bandmates if they like it at all, because if they don't like it, I'll drop it just like ffmpeg drops frames, but if they like it, I'll keep on looking for a way to do this. Maybe someone out there already did it the way you described.



Again about my approach: I _think_ this last error message occurs, because png files don't have timestamps. Could that be the reason why it complains?

Offline

#4 2012-10-14 13:41:35

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: [solved by rtfm] ffmpeg (frame dropping combining images to video)

CRAP!!

This was so EASY!!! I shouldn't have looked how to do this on the web, but use an example of the manpage!

Here's how I did it

ffmpeg -r 25 -i %08d.png out.mkv

and here's how it's done according to the manpage

ffmpeg -i %08d.png -r 25 out.mkv

Doesn't look like it, but this makes a HUGE difference, now I don't have any framedrops smile

The reason is, the way I did it the command line tells ffmpeg that the images have a framerate of 25fps (WRONG!!), the correct way the command line tells ffmpeg, that the output video should have the framerate of 25fps (RIGHT!).

Last edited by Army (2012-10-14 13:41:58)

Offline

#5 2012-10-14 20:52:45

DrZaius
Member
Registered: 2008-01-02
Posts: 170

Re: [solved by rtfm] ffmpeg (frame dropping combining images to video)

Army wrote:

The reason is, the way I did it the command line tells ffmpeg that the images have a framerate of 25fps (WRONG!!), the correct way the command line tells ffmpeg, that the output video should have the framerate of 25fps (RIGHT!).

I don't understand how this makes any difference unless I'm missing something obvious here. By default, IIRC, ffmpeg will use an input frame rate of 25 for image inputs which just happens to be the number you are using. Adding a frame rate as an input option will automatically allow the output to inherit the same frame rate, and if you only declare an output frame rate (other than 25) you will end up with dropped or duplicated frames. ffmpeg will print the number of dropped or duplicated frames near the end of the console output.

As an input option:

$ ffmpeg -r 25 -i %04d.jpg -t 10 -preset ultrafast -y output.mp4
[...]
Input #0, image2, from '%04d.jpg':
  Duration: 00:00:28.80, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj420p, 960x720 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn, 25 tbc
[...]
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf54.29.104
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 960x720 [SAR 1:1 DAR 4:3], q=-1--1, 25 tbn, 25 tbc

As an output option:

$ ffmpeg -i %04d.jpg -r 25 -t 10 -preset ultrafast -y output3.mp4
[...]
Input #0, image2, from '%04d.jpg':
  Duration: 00:00:28.80, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj420p, 960x720 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn, 25 tbc
[...]
Output #0, mp4, to 'output3.mp4':
  Metadata:
    encoder         : Lavf54.29.104
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 960x720 [SAR 1:1 DAR 4:3], q=-1--1, 25 tbn, 25 tbc

Default:

$ ffmpeg -i %04d.jpg -t 10 -preset ultrafast -y output2.mp4
[...]
Input #0, image2, from '%04d.jpg':
  Duration: 00:00:28.80, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj420p, 960x720 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn, 25 tbc
[...]
Output #0, mp4, to 'output2.mp4':
  Metadata:
    encoder         : Lavf54.29.104
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 960x720 [SAR 1:1 DAR 4:3], q=-1--1, 25 tbn, 25 tbc

Notice that all of the frame rates are the same and so are the md5sums.

$ md5sum output.mp4 output2.mp4 output3.mp4 
6427573965742960c5d2bc9f1bf8dbfb  output.mp4
6427573965742960c5d2bc9f1bf8dbfb  output2.mp4
6427573965742960c5d2bc9f1bf8dbfb  output3.mp4

I know you used mkv, but the md5sums change due to what I assume is the "Unique ID" metadata (but the numbers are the same if I use the framemd5 muxer in ffmpeg) and libx264 is default for .mp4 and .mkv.

How did you know you were dropping frames?

Last edited by DrZaius (2012-10-14 20:57:03)


Damned dirty ape.

Offline

Board footer

Powered by FluxBB