I am trying to convert a bunch of FLV files to MP4. I've tried Handbrake, ffmpeg, and mencoder, and none can convert properly. The problem is that the resulting file time does not match up with the known length of the video, so the video is way out of sync
Here's an example from one of the files:Known length: 3:56In this case, the video stream is much too long. I believe this is because of a variable framerate of the video inside the FLV file. FFmpeg sees the source FLV file like this:
Audio stream: 3:56
Video stream: 7:52
Duration: 00:03:56.33, start: 0.000000, bitrate: 223 kb/sI used FLV_extract to split the video and audio streams into avi and mp3 files, and ffmpeg sees them like this:
Stream #0:0: Video: vp6f, yuv420p, 800x600, 15 tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
Input #0, avi, from 'Section 1.avi':
Duration: 00:07:52.67, start: 0.000000, bitrate: 77 kb/s
Stream #0:0: Video: vp6f (VP6F / 0x46365056), yuv420p, 800x608, 7.50 tbr, 7.50 tbn, 7.50 tbc
Input #0, mp3, from 'Section 1.mp3':One thing I notice is that the tbr, tbn, and tbc are different for the video stream depending on if it's within the FLV file or separate.
Duration: 00:03:56.85, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
I'm not really sure where to go from here. Does anyone have any suggestions on handling this?
+ Reply to Thread
Results 1 to 11 of 11
-
-
The time is half, and 7.5 fps is half of 15 fps. So force the frame rate to 15 and it should be the same length and in sync
Look at the timecodes when you used flv extract - are they variable ? MP4 supports VFR so if source was truly VFR, you can use mp4fpsmod to make the VFR MP4 with the same timecodes . FFmpeg should actually convert a VFR FLV to VFR MP4, keeping VFR, but you said it didn't work...post the command line used -
I had problems with VFR in the past, but the latest & greatest win bin of FFMPEG appears to do a good job of taking VFR and putting it to CFR.
I suggest simply defining the desired frame rate will induce CFR in the output video and video/audio length should "match", if that makes sense...
Let us know...
Andrew -
Here's the command line I am now using:
ffmpeg -i ^
I am using the iPad3 profile from this site: https://develop.participatoryculture.org/index.php/ConversionMatrix
"Section 1.flv" ^
-acodec aac -ac 2 -strict experimental -ab 128k ^
-vcodec libx264 ^
-preset slow -profile:v baseline -level 30 ^
-filter:v "setpts=0.4*PTS" ^
-maxrate 10000000 -bufsize 10000000 ^
-b:v 1200k ^
-f mp4 -threads 0 ^
"Section 1.mp4"
However, I tried forcing the framerate with "-r 15", but it did not seem to have an effect. I did have success by adding a filter though:-filter:v "setpts=0.4*PTS"
as I have included in the above command line. I tried using 0.5 as the speed value, but for some reason that didn't slow the video down enough, but 0.4 hits exactly the right length. I'm sure there's something I'm not understanding there, but it's mostly working.
I say "mostly" because ffmpeg is now crashing towards the end of the file. The result is that the audio continues but the video stops. The crash seems to generally line up with the spot the video stop, just near the end.
Edit: I'm using the most recent Windows build of ffmpeg, Feb 17 2013 02:37:45 -
Hi
Try using -vsync 1 instead of your filter.
ffmpeg -i ^
"Section 1.flv" ^
-acodec aac -ac 2 -strict experimental -ab 128k ^
-vcodec libx264 ^
-preset slow -profile:v baseline -level 30 ^
-vsync 1 -r 25 ^
-maxrate 10000000 -bufsize 10000000 ^
-b:v 1200k ^
-f mp4 -threads 0 ^
"Section 1.mp4" -
Here is a link to the file (6.5MB): https://dl.dropbox.com/u/8634176/Section%201.flv
@bat999: I tried that but it did not help. Thanks for the suggestion. -
I think bat99 had a typo, he probably meant -r 15 , not -r 25 -- did you test that?
This is actually a CFR file , and it works ok if you route it through avisynth's directshowsource (with lav filters splitter, ffdshow decoding) , or ffms2 if you force the framerate to 15 (using AssumeFPS(15) ) . You can still use ffmpeg to encode , or whatever encoder . This suggests it's a decoding issue with ffmpeg (ffms2 is derived from ffmpeg libraries and exhibts similar framerate issues , but forcing it to 15 works ok)
Where was the crash that you mentioned? There is a small decoding glitch near the very end (the last few frames), but it doesn't affect linear playback unless you seek directly to that area
eg. ffms2 , ffmpeg to encode
EDIT: attachment removed by requestLast edited by poisondeathray; 4th Mar 2013 at 08:29.
-
There seems to be a number of spots in the video that, while most players will play through, FFmpeg will not like. They are areas of incomplete or corrupted areas of 00 00 00 00 00 before an incorrect audio or video start segment.
If you run FLVCheck and FFmpeg to copy audio and video you get:
and if you attempt to do a copy:
You get this result with FLVCheck:
If you copy it a gain you will get a correct check but the video will only be the first 21 seconds of the film( where the first bad area is):
I've had this problem my self and its caused by the invalid areas in the video. It can be corrected with a HxD editor but its time consuming and you need a good knowledge of FLV file format. -
Thanks for all of your input, I really appreciate it. I finally cracked it using flv extractor and ffmpeg. This is what I did:
- Extract audio and video into separate files from FLV file with FLV Extractor
- Analyze extracted video files (saved as AVI). The video files had a bunch of different frame rates. Some had 15 fps, others 7.5, and one had 5 fps
- Converted video files using ffmpeg and the setpts filter to adjust video speed and force framerate to 15fps for each file. Unlike my previous attempt with setfps, the multipliers were exactly correct, so the audio stream in the previous file must have been affecting the calculation. Ffmpeg crashed at the end of processing each of these files, but the resulting mp4 video file seems to be correct (well, it plays back OK at least).
- Muxxed video and audio, while converting audio from mp3 to aac, into a final mp4 file.
- Resulting mp4 files play correctly and video is synced as much as needed for these files (some video and audio files were slightly longer or shorter in total duration by a second or so), but not enough to make a difference here.
-
Just to add an additional method... I used the Section 1.FLV file and loaded into Virtualdub and used compression of AVC codec and set frame rate to make audio and video same length (14.967). I saved to both avi and to mp4 formats with virtualdub and they were as identical as i could determine with a duration of 3m 56s each and the audio now played through the complete video.
Similar Threads
-
Bad File / Variable Frame rate from Skype Cap
By AceBlade258 in forum Video Streaming DownloadingReplies: 4Last Post: 4th Mar 2013, 13:00 -
Converting MKV to PS3 with a variable frame rate
By hookeyed in forum Video ConversionReplies: 4Last Post: 20th Jun 2010, 07:38 -
[SOLVED!] Converting Variable Sample Rate to Constant Sample Rate
By Midzuki in forum AudioReplies: 17Last Post: 24th May 2009, 10:26 -
Variable frame rate (vfr) and 120 (119.88) fps video playback big problem
By lovyagin in forum Software PlayingReplies: 0Last Post: 22nd May 2009, 04:40 -
Variable Frame Rate
By neoblood in forum Video ConversionReplies: 3Last Post: 20th Apr 2009, 15:50