Log in

View Full Version : Converting H264 FLV file to MP4 without reencoding


BlueCop
16th July 2008, 02:30
ok i have a flv file with h264 video track and an mp4a audio track.

i thought ffmpeg would remux this to mp4 for me with this line

ffmpeg -i INPUT.flv -vcodec copy -acodec copy OUTPUT.mp4

but it gives me this output

[flv @ 00B20800]Bad picture start code
[flv @ 00B20800]header damaged
Input #0, flv, from 'INPUT.flv':
Duration: 00:22:24.25, start: 0.015000, bitrate: N/A
Stream #0.0: Video: h264, yuv420p, 1000.00 tb(r)
Stream #0.1: Audio: libfaad, 44100 Hz, stereo
Output #0, mp4, to 'OUTPUT.mp4':
Stream #0.0: Video: libx264, yuv420p, q=2-31, 1000.00 tb(c)
Stream #0.1: Audio: libfaac, 44100 Hz, stereo
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
[mp4 @ 00B0AD84]dimensions not set
Could not write header for output file #0 (incorrect codec parameters ?)
when i play the file with ffplay it plays fine with perfect sync.
i have tried various settings and it just won't output the video or the audio track to a different format.

here is the extracted meta data from the flv file
<duration>
1344.256
</duration>
<moovposition>
36
</moovposition>
<width>
640
</width>
<height>
480
</height>
<videocodecid>
avc1
</videocodecid>
<audiocodecid>
mp4a
</audiocodecid>
<avcprofile>
100
</avcprofile>
<avclevel>
51
</avclevel>
<aacaot>
2
</aacaot>
<videoframerate>
0
</videoframerate>
<audiosamplerate>
48000
</audiosamplerate>
<audiochannels>
2
</audiochannels>
<trackinfo>
<value1>
<length>
32260228
</length>
<timescale>
24000
</timescale>
<language>
eng
</language>
<sampledescription>
<value1>
<sampletype>
avc1
</sampletype>
</value1>
</sampledescription>
</value1>
<value2>
<length>
64524288
</length>
<timescale>
48000
</timescale>
<language>
eng
</language>
<sampledescription>
<value1>
<sampletype>
mp4a
</sampletype>
</value1>
</sampledescription>
</value2>
</trackinfo>


could anyone point me to what i am doing wrong? or maybe a utility that could do what i want.

Thanks in advance for any help

Sharktooth
16th July 2008, 02:33
first of all, ffmpeg mp4 muxer is broken.
try demuxing the raw streams then remux them with mp4box.

BlueCop
16th July 2008, 02:55
ffmpeg -i S1E1.flv -vn -acodec copy audio.aac

works for extracting the audio

i tried this for the video and it doesn't work and i am not sure what parameters might be incorrect

ffmpeg -s 640x480 -i S1E1.flv -an -vcodec copy video.h264


FFmpeg version SVN-r14196, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --enable-memalign-hack --enable-postproc --enable-swscale --ena
ble-gpl --enable-libfaac --enable-libfaad --enable-libgsm --enable-libmp3lame --
enable-libvorbis --enable-libtheora --enable-libx264 --enable-libxvid --disable-
ffserver --disable-vhook --enable-avisynth --enable-pthreads
libavutil version: 49.7.0
libavcodec version: 51.60.0
libavformat version: 52.17.0
libavdevice version: 52.0.0
built on Jul 13 2008 01:38:20, gcc: 4.2.4 (TDM-1 for MinGW)
[flv @ 00AD0900]Bad picture start code
[flv @ 00AD0900]header damaged
...
[flv @ 00AD0900]Bad picture start code
[flv @ 00AD0900]header damaged
Input #0, flv, from 'S1E1.flv':
Duration: 00:22:24.25, start: 0.015000, bitrate: N/A
Stream #0.0: Video: h264, yuv420p, 1000.00 tb(r)
Stream #0.1: Audio: libfaad, 48000 Hz, stereo
Output #0, h264, to 'video.h264':
Stream #0.0: Video: libx264, yuv420p, q=2-31, 1000.00 tb(c)
Stream mapping:
Stream #0.0 -> #0.0
[h264 @ 00ABAC4C]dimensions not set
Could not write header for output file #0 (incorrect codec parameters ?)

i have tried various builds with the same result.

i am not sure what to do about "Could not write header for output file #0 (incorrect codec parameters ?)" and
"[flv @ 00AD0900]Bad picture start code
[flv @ 00AD0900]header damaged"

I normally like to solve my own problems but this is simply a mystery to me. anyone have any suggestions?

fields_g
16th July 2008, 05:29
I'm hoping for an easy solution for you and may be way off, but are you sure it isn't mp4 already? The errors may be a symptom of it not being an actual FLV file. Flash is capable of reading mp4 files that have been written with a FLV extension. I've seen this done by some in order to use them in certain flash player apps. It's really easy to rename and see. The errors may be a symptom of it not being an actual FLV file.

BlueCop
16th July 2008, 06:46
I'm hoping for an easy solution for you and may be way off, but are you sure it isn't mp4 already? The errors may be a symptom of it not being an actual FLV file. Flash is capable of reading mp4 files that have been written with a FLV extension. I've seen this done by some in order to use them in certain flash player apps. It's really easy to rename and see. The errors may be a symptom of it not being an actual FLV file.
thanks for the suggestion but i actually checked that and it is definitely flv container. i verify that 100% with a hexeditor and various utilities.

i also tried flv extract and shot a pm to the creator to see if he could add h264 and aac support.

again thanks for any replies and i hope someone can help me solve my problem

nm
16th July 2008, 07:02
Would MPlayer demux the streams:mplayer -dumpvideo -dumpfile video.264 input.flv
(and then audio: mplayer -dumpaudio -dumpfile audio.aac input.flv)

bond
16th July 2008, 19:22
first of all, ffmpeg mp4 muxer is broken.
try demuxing the raw streams then remux them with mp4box.in what way is it broken?

shae
16th July 2008, 20:42
I think there's an FLV input plugin for VirtualDub 1.8x. You might be able to use as a stepping stone.

Placio74
16th July 2008, 22:30
I think there's an FLV input plugin for VirtualDub 1.8x. You might be able to use as a stepping stone.
But... this plugin not handle FLV with AVC/AAC.


BTW
This FLV video probably maked by 'older' FFmpeg build (maybe r13537). Later Problematic to change container.
But if FLV maked by FFmpeg r14196 - later, no problem to change container (when i'm try).

BlueCop
16th July 2008, 22:51
Would MPlayer demux the streams:mplayer -dumpvideo -dumpfile video.264 input.flv
(and then audio: mplayer -dumpaudio -dumpfile audio.aac input.flv)

mplayer does demux the video stream but i can't get it to play or mux with anything else. i think it might have currupt headers or something.

The orginal flv does play in mplayer. its gives me this output when playing with mplayer

[flv @ 00EAF2D0]Bad picture start code
[flv @ 00EAF2D0]header damaged
[lavf] Video stream found, -vid 0
[lavf] Audio stream found, -aid 1
VIDEO: [H264] 0x0 0bpp 1000.000 fps 0.0 kbps ( 0.0 kbyte/s)
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
==========================================================================
Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)
FAAD: compressed input bitrate missing, assuming 128kbit/s!
AUDIO: 48000 Hz, 2 ch, s16le, 128.0 kbit/8.33% (ratio: 16000->192000)
Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio) decoder)
==========================================================================
AO: [dsound] 48000Hz 2ch s16le (2 bytes per sample)
Starting playback...
[h264 @ 0peaf2d0]AVC: nal size 0
[h264 @ 0peaf2d0]no frame!
Error while decoding frame!
[h264 @ 0peaf2d0]AVC: nal size 16777216
[h264 @ 0peaf2d0]no frame!
Error while decoding frame!
VDec: vo config request - 640 x 480 (preferred colorspace: Planar YV12)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 1.33:1 - prescaling to correct movie aspect.
VO: [directx] 640x480 => 640x480 Planar YV12


shae: i did try the flv input plugin for virtualdub but it has the same auther as flv extract and it doesn't support AVC/AAC as placio74 said.

also i have been using ffmpeg SVN-r14196

BlueCop
17th July 2008, 10:15
here is a sample flv that contains avc h264 and aac so someone might be able to help me solve my issue. thanks for any assistance.

http://kotuha.com/file/xWDiB-sample.html

smok3
17th July 2008, 12:03
not really helpfull, but i can confirm that
FFmpeg version Sherpya-r13537
can't remux any AVC flv to mp4.

BlueCop
18th July 2008, 09:52
I submitted a bug report with sample to ffmpeg so hopefully they can fix this issue in the future.

Thanks for all replies. i will post back if i find that this issue has been solved and what svn revision it works in.

Sharktooth
18th July 2008, 14:07
in what way is it broken?
it produces uncompliant/incomplete mp4 files/srtructures.

robinsonlove
20th July 2008, 14:25
FFMPEG NO sound!

BlueCop
22nd July 2008, 08:49
FFMPEG NO sound!

what????

Placio74
22nd July 2008, 10:28
not really helpfull, but i can confirm that
FFmpeg version Sherpya-r13537
can't remux any AVC flv to mp4.
However r14277 can, but not this specific sample file.

it produces uncompliant/incomplete mp4 files/srtructures.
Maybe, but I'm afraid it's not relate and it's problem with specific FLV file.
This sample file can't remux (and can't reencode) to MP4, but to other containers too.

I'm curious what's source (site) this file and how it's create.

BlueCop
22nd July 2008, 10:53
it is saved from a h264/aac rtmp streamed video clips from hulu

its not just one flv file. its every h264/acc flv file from the site except the HD ones which are actually mp4 container.

what is curious to me is that it plays back perfectly with ffplay and mplayer but does not remux correctly? anyway i hope there is a solution in the future.

Also i have tried the latest mplayer/mencoder svn and it can reencode these files and have correct sync if i specify the correct fps.

I would like to be able to play these on my ipod and or with xbmc and in the current container its not possible.

BlueCop
31st July 2008, 18:32
Fixed in r14480. See "[FFmpeg-devel] [PATCH] skip flv video info / command
frames" for explanation.

those ffmpeg devs work fast. I just did some test remuxes of some of the files and it seems to work fine.