How can I convert .264 file to .mp4

56,774

Solution 1

This is easy with ffmpeg:

ffmpeg -framerate 24 -i input.264 -c copy output.mp4
  • This simply stream copies (re-muxes) the video so there is no unnecessary re-encoding occurring; therefore the quality is preserved and the whole process is quick.

  • Frame rate is by default assumed to be 25. You can change this with the -framerate input option. Typical values are 30000/1001, 25 (default), 24000/1001, 24, or frame rate aliases such as ntsc, ntsc-film, or pal.

  • If you don't know the frame rate, you can perform the conversion using your best guess as to the frame rate, and then compare the running duration of the output file with the input file running duration and then calculate the actual frame rate. e.g. assume 24 fps and actual running time of 1:00:00 (60 mins) if resulting file has running time of 1:02:30 (62.5 mins) then actual frame rate is 25 fps (24 * 62.5 / 60)

Solution 2

Try these commands :

sudo apt-get install x264
x264 raw_stream.264 -o playable_video.mp4

Run the MP4 files in VLC

Solution 3

I wrote a simple bash script to convert all the files in a directory. Make sure the directory only contains the source files since the operation will run on all files in a given directory.

touch ./convert
chmod +x ./convert

edit convert

#!/bin/bash
for f in *; do
    if [ -f "$f" ] && [ "$f" != "convert" ]; then
        ffmpeg -framerate 25 -i "$f" -c copy "$f.mp4"
    fi
done

Drop in a directory with only the source files, double click and choose run

This script assumes ffmpeg is set up on you system. Not sure which libs are needed, this is what I installed before running: sudo apt install ffmpeg x264 x265 h264enc mencoder mplayer

Only run it once

Share:
56,774

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I want to convert an elementary stream(.264) to container format(.mp4). Can someone please help me on this? How can I use ffmpeg to do this task? What are all the other methods that could accomplish the same task?

  • llogan
    llogan over 8 years
    This re-encodes for no reason. Better to just re-mux.
  • David Foerster
    David Foerster about 7 years
    One should note that raw H.264 streams don't carry a rate information, so FFmpeg will display a warning and default to 25 frames/second. If you want a different frame rate you can use the -r switch, e. g. -r 30 for 30 frames/second.
  • llogan
    llogan about 7 years
    @DavidFoerster Yes, good point, but the H.264 demuxer uses -framerate instead of -r.
  • David Foerster
    David Foerster about 7 years
    You're correct. I should have read the entire paragraph in the FFmpeg documentation: “If in doubt use -framerate instead of the input option -r.” For some reason -framerate isn't documented in this manual here though.
  • llogan
    llogan about 7 years
    @DavidFoerster Which man page?
  • David Foerster
    David Foerster about 7 years
    That of ffmpeg(1) (Ctrl+F for -framrate). There's documentation for it in the avfoundation input device section but it doesn't look like it applies to other cases.
  • Hugo Zink
    Hugo Zink over 4 years
    This gives me an error saying "output file #0 does not contain any stream". The input is a raw .h264 file. Any ideas?
  • llogan
    llogan over 4 years
    @HugoZink Need to see your command and the complete log. You can use a pastebin site. Sharing the h.264 file would be helpful if possible.
  • MotsManish
    MotsManish over 4 years
    When the video is played directly in the IP camera app, audio is present, but when the exported .264 file from camera storage is converted using the above command and played in VLC or other video apps there is no sound, any ideas? The conversion log also reads: video:535kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.255534%
  • llogan
    llogan over 4 years
    @MotsManish .h264/.264 is raw H.264 video: it has no audio. Does the original file as pplayed by the app have audio? Is the audio in a separate file?
  • MotsManish
    MotsManish over 4 years
    @llogan, thanks for your comment, Yes, the video when played in camera app has audio and I confirmed in the memory card, the audio file is not separate.
  • llogan
    llogan over 4 years
    @MotsManish I recommend asking a new question. In the question you should provide the complete output of ffmpeg -i input where input is the file from the camera.
  • llogan
    llogan about 3 years
    "this is what I installed before running: sudo apt install ffmpeg x264 x265 h264enc mencoder mplayer" Only ffmpeg is needed for this script, so the other packages are not necessary.
  • Admin
    Admin about 2 years
    this was awesome... <3