How to convert .flv video into .h264 format with FFmpeg?

14,306

The solution is that you need a container format. Raw h.264 does not have any timing information for a video which is why your player is playing it very fast.

Also your command is all messed up. Do you want audio in your output or not? If yes then you need to specify a container format which will have both audio and video.

Either change your output to a mp4

ffmpeg -i input_file -c:a copy -c:v libx264 -profile:v baseline out.mp4

or some other container. If you want a video only stream remove the audio options and add -an.

If you want to use AAC audio instead of whatever the FLV file has:

ffmpeg -i input_file -c:a aac -strict -2 -b:a 128k -c:v libx264 -profile:v baseline out.mp4

If your ffmpeg does not have the -c or -profile options, update to a more recent version.

Share:
14,306
Shishir Mudliyar
Author by

Shishir Mudliyar

Updated on June 12, 2022

Comments

  • Shishir Mudliyar
    Shishir Mudliyar about 2 years

    I want to convert from .flv to .h264 format.

    Problem: I did a conversion from FLV to H264 format but my converted video (.h264) is running so fast (just like we'd click on a fast forward button).

    I used the following command:

    ffmpeg -i example.flv -sameq -vcodec libx264 -vpre default -ar 22050 output.h264
    
  • Shishir Mudliyar
    Shishir Mudliyar over 11 years
    I was getting error pts after filters MISSING No pts value from demuxer to use for frame!,?% 0 0 pts after filters MISSING No pts value from demuxer to use for frame!,?% 0 0 pts after filters MISSING No pts value from demuxer to use for frame!,?% 0 0
  • Shishir Mudliyar
    Shishir Mudliyar over 11 years
    I used -r 30 in my command :: ffmpeg -i example.flv -r 30 -sameq -vcodec libx264 -vpre default -ar 22050 output.h264 but the result wouldn't change , video still running fast forward
  • slhck
    slhck over 11 years
    -vpre does not exist on any recent FFmpeg version and should be avoided. Use -profile:v to specify profiles and -preset slow etc. for encoding presets.
  • slhck
    slhck over 11 years
    This will never work since the .h264 raw format does not contain any information about how many frames per second are stored.
  • seba.wagner
    seba.wagner over 11 years
    However the resulting .mp4 must have some kind of frame rate?
  • slhck
    slhck over 11 years
    Well, there is no "resulting MP4" file if you output the raw h.264 bitstream to a h264 file. A h264 file only contains the video data, nothing else. You would need two wrap it in a container like MP4 in order to specify how many frames per second should be shown. (By the way, don't forget to notify other users with @slhck, otherwise they don't get a reply)
  • seba.wagner
    seba.wagner over 11 years
    @slhck thanks for the advice, I was reading your ffmpeg command with the resulting .mp4 file instead of the initial one :)
  • Shishir Mudliyar
    Shishir Mudliyar over 11 years
    @av501 following command is working fine to produce mp4 video with h.264 format but the audio is not working in IPhone (its working in Android mobiles) ffmpeg -i example.flv -r 25 -sameq -ab 128kb -vcodec libx264 -vpre default -s 320x240 -b 768kb -ar 44100 -acodec copy output.mp4 and when i used acodec = aac , ffmpeg show me following message "encoder 'aac' is experimental and might produce bad results. Add '-strict experimental' if you want to use it."
  • Shishir Mudliyar
    Shishir Mudliyar over 11 years
    @slhck when i used -preset slow i got following message in ffmpeg "Unrecognized option 'preset'"
  • slhck
    slhck over 11 years
    @ShishirMudliyar Make sure you run the latest version of FFmpeg or at least something newer than 0.9. vpre has been deprecated for quite some time now – several hundreds of bugs have been fixed since your version.
  • slhck
    slhck over 11 years
    @ShishirMudliyar I added another example with AAC audio, which you will probably need when targeting iPhone/Android devices. But maybe you could make your question more clear and tell us what exactly you want to do (i.e. which devices) and what the input file actually contains.
  • Shishir Mudliyar
    Shishir Mudliyar over 11 years
    @slhck My all input files are .flv type ( video audio both) and i need to convert this flv into h.264 formate so that we can run that video into Iphone/Android.
  • av501
    av501 over 11 years
    @ShishirMudliyar, to run on iphone/android you still need to put it in a mp4. They do not play raw h.264 files. H.264 is a codec for the video which forms an elementary stream inside the mp4 container. To get the files playing in android/ios depending on set of devices you are targeting you may also want to set bitrate resolution and frame rate to control the level and the profile with ref frames = 1 for constraned baseline if you want a single file to play across devices. Else seperately encode for subsets which can play main profile & higher quality files.Read up a bit on codecs/containers
  • slhck
    slhck over 11 years
    @ShishirMudliyar Please do us a favor and include the full uncut command line output from FFmpeg in your question. This is absolutely important for any FFmpeg question, also those you might ask in the future. Also check out What are the differences between H.264 Profiles? and What is a Codec (e.g. DivX?), and how does it differ from a File Format (e.g. MPG)?
  • Shishir Mudliyar
    Shishir Mudliyar over 11 years
    @slhck Now following cmd is creating video which is running good in Android/Iphone for video ,audio both ffmpeg -i example.flv -r 25 -sameq -b:a 128k -vcodec libx264 -preset slow -s 320x240 -b:v 768k -ar 44100 -acodec aac -strict -2 output.mp4 ..... i upgrade my ffmpeg to 0.10 ....really thanks for your valuable support
  • Shishir Mudliyar
    Shishir Mudliyar over 11 years
    @av501 Now following cmd is creating video which is running good in Android/Iphone for video ,audio both ffmpeg -i example.flv -r 25 -sameq -b:a 128k -vcodec libx264 -preset slow -s 320x240 -b:v 768k -ar 44100 -acodec aac -strict -2 output.mp4 ..... i upgrade my ffmpeg to 0.10 ....really thanks for your valuable support
  • slhck
    slhck over 11 years
    @ShishirMudliyar You're welcome. Feel free to accept av501's answer by clicking the green checkmark next to it! But please don't use the sameq option. It doesn't do what you want, it doesn't even exist anymore in FFmpeg 1.0. And next time you ask a question about FFmpeg, please ask it on Super User, and include the full command line output, not just the command you're using. Thanks!
  • Pus
    Pus over 10 years
    @slhck i got this Unrecognized option 'c:v' error how can i fix this?
  • slhck
    slhck over 10 years
    @Pus Use a recent version of FFmpeg. If yours does not have the option it's quite outdated. You can build it yourself or download a static build from their homepage.