How to convert m4v and wmv videos to mp4 format using ffmpeg?
I am using ffmpeg to convert videos to mp4 in my PHPMotion project. I am not able to convert wmv and m4v video to mp4 format. I’ve pasted the command that I used to convert wmv and m4v:
When I use this codes, i got an error message:
How can I solve this issue?
3 Answers 3
For those who still find this question today, because they’re trying to play m4v files that their hardware or software generated, but none of the players they try will play them: m4v is not just a playable media container, but is also used as a pure stream format by a number of commonly used tools and video capture devices, so that it can be used to burn the video directly to disc. This is especially likely when you’re using something like Adobe’s Creative Suite set of tools for video production.
To turn an «unplayable» m4v stream (that your capture device/software suggests should totally be playable) into the kind of video file you’re used to, tell ffmpeg to copy the stream into an mp4 container:
Or, using the combined a/v codec shorthand flag:
No actual encoding happens, so this will only take a few seconds, if not less. Done deal.
Convert a video to MP4 (H.264/AAC) with ffmpeg
If I don’t make a mistake, Safari currently need MP4 (H.264/AAC) video encoded for the HTML5 element.
So I tried to convert a video to this format with ffmpeg . However when I enter the shell command ffmpeg -i video.flv video.mp4 , the returned error is :
Seems stream 0 codec frame rate differs from container frame rate: 2000.00 (2000/1) -> 29.92 (359/12) Input #0, flv, from ‘video.flv’:
Duration: 00:05:01.20, start: 0.000000, bitrate: 66 kb/s Stream #0.0: Video: h264, yuv420p, 320×240 [PAR 1:1 DAR 4:3], 66 kb/s, 29.92 tbr, 1k tbn, 2k tbc Stream #0.1: Audio: aac, 22050 Hz, stereo, s16 Output #0, mp4, to ‘video.mp4’: Stream #0.0: Video: mpeg4, yuv420p, 320×240 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 29.92 tbc Stream #0.1: Audio: 0x0000, 22050 Hz, stereo, s16, 64 kb/s Stream mapping: Stream #0.0 -> #0.0
Stream #0.1 -> #0.1 Unsupported codec for output stream #0.1
An AAC codec is required but I’m quite newbie with ubuntu and I dont really now how to fix this problem. I’m using Ubuntu 9.10 Karmik Koala (for amd64).
How to convert .mkv file into .mp4 file losslessly?
I need to convert a video file from Matroska container into mp4 container. Matroska file contains one h.264 video track and one AC3 sound track. It should be possible to do this losslessly, but how to do it with native Ubuntu tools?
Transcoding is not an option.
6 Answers 6
Perhaps the easiest tool for that is ffmpeg , or avconv from the libav-tools package. Libav is a fork of FFmpeg, which Ubuntu switched to for a few years until Ubuntu 15.04. It is one of the backends for many of the GUI tools mentioned in other answers.
Changing container without re-enconding content could not be simpler:
It auto-detects a Matroska to MP4 container conversion based on input/output filenames.
-codec copy stream copies, or «re-muxes», the streams from the input to the output without re-encoding. Think of it like a copy and paste.
Default stream selection behavior is to select only one stream per stream type. For example, if your input has two video streams and one audio stream then only the video stream with the largest frame size will be selected. Add -map 0 if you want to select all streams from the input.
Some containers may not support some formats. So check if your chosen container format, be it mkv , mp4 or even avi has support for all the content in your files (video, audio, subtitles, data, etc). For example, mp4 does not support SubRip subtitles ( .srt files).
dvlden / ffmpeg.md
This is my personal list of functions that I wrote for converting mov files to mp4 !
Flag | Options | Description |
---|---|---|
-codec:a | libfaac, libfdk_aac, libvorbis | Audio Codec |
-quality | best, good, realtime | Video Quality |
-b:a | 128k, 192k, 256k, 320k | Audio Bitrate |
-codec:v | mpeg4, libx264, libvpx-vp9 | Video Codec |
-b:v | 1000, 2500, 5000, 8000 | Video Bitrate |
-vf scale | -1:X | Resize Video (X is height) |
-qmin 10 -qmax 42 | . | https://gist.github.com/dvlden/b9d923cb31775f92fa54eb8c39ccd5a9#gistcomment-2972745 |
ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 4500k -minrate 4500k -maxrate 9000k -bufsize 9000k -vf scale=-1:1080 output.mp4
ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 2500k -minrate 1500k -maxrate 4000k -bufsize 5000k -vf scale=-1:720 output.mp4
ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 1000k -minrate 500k -maxrate 2000k -bufsize 2000k -vf scale=854:480 output.mp4
ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 750k -minrate 400k -maxrate 1000k -bufsize 1500k -vf scale=-1:360 output.mp4
This comment has been minimized.
Copy link Quote reply
C0DEF52 commented Aug 19, 2018
Great list, thank you! Also I’ve found that it is possible to use -2 instead of -1 in scale argument. It will automatically fix value to be divisible by 2.
This comment has been minimized.
Copy link Quote reply
ealgase commented Feb 17, 2019
Thanks, this is pretty useful!
This comment has been minimized.
Copy link Quote reply
eladkarako commented Mar 16, 2019
@C0DEF52 using -2 for MP4 scaling is a very good tip,
much better then my original solution to format=pix_fmts=yuv420p,crop=trunc(in_w/2)*2:trunc(in_h/2)*2,scale=-1:360 trac.ffmpeg.org/wiki/Scaling
This comment has been minimized.
Copy link Quote reply
Cool-Programmer commented Apr 25, 2019 •
Thanks. If someone is getting libfdk_aac unknown lib error, just use «aac» instead
Also this one is for 240p
ffmpeg -i inputVideo.mp4 -threads 0 -preset slow -s 320×240 -c:v libx264 outputVideo.mp4
This comment has been minimized.
Copy link Quote reply
ADoncel commented Jul 17, 2019
-qmin and -qmax refer to Quantization and it’s important in signal analysis, this picture resume what it «does»:
This comment has been minimized.
Copy link Quote reply
dvlden commented Jul 17, 2019
Thank you for that summary. Highly helpful! @ADoncel
This comment has been minimized.
Copy link Quote reply
theraw commented Nov 25, 2019
This comment has been minimized.
Copy link Quote reply
dan-norris commented Feb 3, 2020
Thanks. If someone is getting libfdk_aac unknown lib error, just use «aac» instead
Also this one is for 240p
ffmpeg -i inputVideo.mp4 -threads 0 -preset slow -s 320×240 -c:v libx264 outputVideo.mp4
This comment has been minimized.
Copy link Quote reply
arcanosam commented Mar 4, 2020
Thanks. If someone is getting libfdk_aac unknown lib error, just use «aac» instead
Also this one is for 240p
ffmpeg -i inputVideo.mp4 -threads 0 -preset slow -s 320×240 -c:v libx264 outputVideo.mp4
This comment has been minimized.
Copy link Quote reply
eminyalcin commented May 13, 2020 •
[solved]hi brothers. help me please. i make screen recorder in vb.net only for me. i use m.e. encoder. so my output file name is date hours.xesc.
i need to convert xesc to mp4 files. i use ffmpeg for all jpeg files in folder to mp4 file. this is work. but dont work this code.
i choose height and width for screen recorder.
please help me. i need basic code for convert
Dim args, girdi, cikti As String
girdi = «C:\video\ScreenCapture_12.05.2020 17.16.25.xesc» ‘for example
cikti = «C:\videokayit\output.mp4» ‘for example
args = «-i » & girdi & » -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 1000k -minrate 500k -maxrate 2000k -bufsize 2000k -vf scale=854:480 » & cikti
i think ffmpeg need good names.
example
ScreenCapture_11.05.2020 19.37.16.xesc is not work
ScreenCapture_11.05.202019.37.16.xesc is work.
How to convert mpeg to mp4?
I would like to convert an MPEG TS file to MP4. Is there software for Ubuntu that I can buy that just works?
In 13.10 I did the following with success: Edit the file with DVB-CUT and export to MPG. Then open the MPG in WinFF, select MP4 with High Quality preset and convert but in 14.04 this fails with the following error:
2 Answers 2
You could use VLC to convert mpeg files to mp4. To do this:
Click on Media in the menu bar and select «Convert / Save»
In the «File» tab, click on «Add. » button and choose the file to convert from the file browser dialog box that opens up
Click on «Convert / Save» and verify that the source file is exactly the one which you want to convert and give an appropriate file name for the destination file, appended with «.mp4» and choose the format for the destination file. In your case this would be «Video — H.264 + MP3 (MP4)» and then click on «Start»
This may take some time depending upon the length of the file and when it finishes, voila! You have your file ready.