I am using ffmpeg to switch container from mkv to mp4 via this command:
ffmpeg -i filename.mkv -vcodec copy 1.mp4
this is the simplest command that I found when converting from mkv container to mp4 without re-encoding. The output stated otherwise (if I am not mistaken)
This is a small screen shot of the the output:
Where it said Stream Mapping, #0:0 (264 (native)) -> 264 (libx264)). Does this mean that it's re-encoding from x264 to libx264? What Did I do wrong?
Any help is appreciated...
problem solved, specify the audio codec solve my problem...
ffmpeg -i filename.mkv -vcodec copy -acodec copy 1.mp4
Remuxing containers, e.g. MKV or AVI to MP4, with FFmpeg will only keep a single – it tries to choose the best one available – audio and video stream from the input file in the output file. This can be avoided by providing -map 0.
Matroska files frequently contain subtitles in a format not supported in MOV/MPEG containers by FFmpeg, esp. SRT/Subrip or ASS/SSA. They can either simply be dropped with -sn or be converted to a native format like mov_text. (You could also burn hard subtitles into a video stream with filters.)
Sometimes, adding missing information by using heuristics might help. This is activated with -find_stream_info, but I am not sure whether this should be used by default.
I shall assume that built configuration is not important to know (-hide_banner) and only serious problems should be logged to the console (-loglevel warning, alternatively: quiet | panic | fatal | error | warning | info (default) | verbose | debug | trace).
Therefore, a rather universal conversion command looks like this:
$ ffmpeg -find_stream_info -i input.mkv \
-map 0 -codec copy -codec:s mov_text output.mp4 \
-hide_banner -loglevel warning; \
rm input.mkv
For batch processing multiple files on a Windows box within cmd and overwriting existing files (-y), use for:
FOR /r %F IN (*.mkv) DO (#ffmpeg \
-find_stream_info -i "%F" \
-map 0 -codec copy -codec:s mov_text "%~pnF.mp4" \
-hide_banner -loglevel warning -y)
ffmpeg.exe -i input_file_name.mkv output_file_name.mp4
It converts to mp4 but it making a bigger size. :)
For those who use Windows and want to convert a directory of MKV files, throw this batch file in the same directory and execute it:
#ECHO OFF
FOR %%F IN (*.mkv) DO (
ffmpeg -i %%~nF.mkv -acodec copy -vcodec copy %%~nF.mp4
)
Some context in case anyone else is facing the same:
I'd previously recorded my desktop using OBS; the mkv file wasn't accepted by Sony Vegas. I ran the above batch which called ffmpeg on each of the captures and the resultant MP4s were accepted by Sony Vegas.
Related
I'm using ffmpeg to convert files to .mp3 and extract cover images from the metadata.
This works fine for files that have cover images, files that don't throw the error:
Output #1 does not contain any stream
ffmpeg -i kalimba.mp3 -y test.mp3 -acodec copy test.jpg
How can I tell ffmpeg to just ignore streams if they don't exist and continue converting to .mp3 if no cover image exists in the metadata?
First you should check what streams are provided in the file. You can do it with tool ffprobe. Then you run ffmpeg to copy one or two streams.
if [ -n "`ffprobe -show_streams -v quiet kalimba.mp3 | grep '^\[streams\.stream\.1\]'`" ] ; then
# the file has 2 streams
ffmpeg -i kalimba.mp3 -y test.mp3 -acodec copy test.jpg
else
# no cover image
ffmpeg -i kalimba.mp3 -y test.mp3 -acodec copy
fi
I am looking for a better command that can merge both audio & video files into one with a better quality.
I found this command from Muaz Khan's WebRTC APIs.
ffmpeg -i {$audioFile} -i {$videoFile} -map 0:0 -map 1:0 {$mergedFileName}
Later on server i had to add "-strict -2" with this command as on server it says that above command is experimental if I still want to use it you should add "-strict -2" with it.
It is working well but my video file (.webm) with size 2.2MB and audio file (.wav) with size 1.5MB was merged into a new file (.webm) with size 422.5KB. This new video file is having lag.
Also I want the meta information for duration of video is already written on the resulting video file.
Is there any command which can give the merged file without lagging and both video and audio of the new file are of good quality ?
Use
ffmpeg -i {$audioFile} -i {$videoFile} -map 0:0 -c:a libopus -map 1:0 -c:v copy {$mergedFileName}
This will encode only the audio, leaving the video intact. Use libvorbis if libopus isn't present in your FFmpeg.
I loop over some files and convert them with ffmpeg. I provide -vcodec h264. When the input video already is encoded with that codec: will the video stream be copied? How to make sure it's not reencoded in that case? Is it what -sameq was used previously?
You need to use -c:v copy if you want the raw H.264 stream to be passed on without re-encoding:
ffmpeg -i myh264file.mp4 -c:v copy -c:a copy myh264output.mp4
-c:a copy will also copy the audio
-c copy will copy both audio and video as in:
ffmpeg -i myh264file.mp4 -c copy myh264output.mp4
Detecting H.264 streams is not straight forward. You will need to code this.
For the -sameq settings please refer to this statement.
I would recommend upgrading to a recent version of ffmpeg if it is not already done as -vcodec is not used anymore, now it is -c:v.
The documentation on ffmpeg could help you.
i want convert video from any format to mp4. so i am using command:
ffmpeg -i ttt.mp4 -vcodec copy -acodec copy test.mp4
this is working perftectly but now i also add scale in this -s 320:240.
There also many other command for convert LIKE :
ffmpeg -i inputfile.avi -s 320x240 outputfile.avi
but after convert by this command video not play in html5 player
BUT this is not working so tell me in my command how i add scale;
So please provide me solution for this .
Thanks in advance.
You have several problems:
In your command, you have -vcodec copy you cannot scale video without reencoding.
In the command you randomly found on the Internet, they are using AVI, which is not HTML5-compatible.
What you should do is:
ffmpeg -i INPUT -s 320x240 -acodec copy OUT.mp4
Adding to Timothy_G:
Video copy will ignore the video filter chain of ffmpeg, so no scaling is available (man ffmpeg is a great source of information that you will not find on Google). Notice that once you start decoding-filtering-encoding (i.e., no copy) the process will be much slower (x100 time slower or even more). The libx264 is recommended if you want compatibility with all browsers.
$ ffmpeg -i INPUT -s 320x240 -threads 4 -c:a copy -c:v libx264 OUT.mp4
vp9 will provide nearly 50% extra bandwidth saving, but only for supported browsers (Firefox/Chrome), and the encoding will much slower compared to libx264 (that itself is much slower that v:c copy):
$ ffmpeg -i INPUT -s 320x240 -c:a copy -c:v vp9 OUT.webm
Notice that there is a set of formats (containers) accepted by browsers (most admit mp4, some also webm, ...) and for each format there is a set of audio/video codecs accepted. For example you can use mp3 or aac with an mp4 file (container), but not with webm files.
http://en.wikipedia.org/wiki/HTML5_video#Supported_video_formats
Hi i have command to merge video files
but i want to join an image to a video file.
What i am doing:
1) convert image to mp4 using ffmpeg
2) joining this converted video to my selected video using mencoder
but it prommpts an error:
cannot mix video only files with audio-video files try -nosound.
i also added -nosound but with this the resultant file does not contains any audio.
what to do?
ffmpeg command:
-y -i Garden.jpg -s 640x480 converted.mp4
this converted .mp4 file is created properly but with no audio
mencoder command:
-oac mp3lame -ovc lavc -noodml -o output.mp4 converted.mp4 selected.mp4
Please help..
If you target is Windows, converting the result to msmpeg4v2 (avi) or mpeg1video (mpg) or asf (wmv) would probably work best.
Note, ASF files often have .wmv or .wma extensions in Windows. It should also be mentioned that Microsoft claims a patent on the ASF format, and may sue or threaten users who create ASF files with non-Microsoft software. It is strongly advised to avoid ASF where possible.
Read this for full list.
Here is a free command line tool which can join MPEG 1 files:
http://mpgtx.sourceforge.net/#Download
(Windows exe available). Did not try it on my own, however.
EDIT: another alternative may be to utilize VirtualDub. You have to write your merge command to a script and pass the script name per command line:
http://www.virtualdub.org/blog/pivot/entry.php?id=20
However, you have to get yourself through the syntax of the scripting language
http://www.virtualdub.org/docs/vdscript.txt
(I did not try this by myself programmatically, have only used virtual dub via GUI interface to concat video files, which worked really well.)
FFmpeg can accomplish this easily with the following command:
ffmpeg -i vid-1.mp4 -i vid-2.mp4 -ar 44100 -ab 64k -ac 1 -c:a libmp3lame -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]' -map '[v]' -map '[a]' output.mp4