Merge/Join images & video files together using mencoder or ffmpeg - image

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

Related

ffmpeg command to merge file with good quality

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.

ffmpeg Will stream be copied if same codec is requested?

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.

How add scale in my ffmpeg command

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

How to wrap H264 into a mp4 container?

I have a program generating a bunch of raw H264 frames and would like to place that into a mp4 container for streaming.
Anyone know how to do that?
I was thinking I'd use ffmpeg however, this needs to be used commercially and it seems like ffmpeg can only do this through it's x264 library... which uses a GPL license.
Thank you!
If you're looking for the FFMPEG command line to do that, then try the following:
ffmpeg -i "source.h264" -c:v copy -f mp4 "myOutputFile.mp4"
If you have a separate audio file you can add it too:
ffmpeg -i "source.h264" -i "myAudio" -c:v copy -c:a copy -f mp4 "myOutputFile.mp4"
If your audio needs to be encoded as well (for instance codec AAC-LC, bitrate 256kbps):
ffmpeg -i "source.h264" -i "myAudio" -c:v copy -c:a aac -b:a 256k -strict -2 -f mp4 "myOutputFile.mp4"
libmp4v2 is under the MPL and can be used as part of a larger work commercially. It is much lighter than libavformat also.

How to convert an mkv (with subtitles) to something Nexus One friendly?

I have this ffmpeg one-liner that's been good for generating video files for my Nexus One:
ffmpeg -i infile.mkv -acodec aac -s 572x238 -vcodec libx264 -vpre ipod640 -ab 128k -b 512k -f mp4 -strict experimental outfile.mp4
But it does this ignorant of the subtitles in infile.mkv -- usually not a problem, unless I'm dealing with a non-english movie. In cases like this, I'd like to use the Japanese audio track, and the English subtitles.
The funny bit is that I can use mplayer to play it using -alang and -slang, but don't know how to use mencoder to make Nexus One friendly videos. I can use ffmpeg to generate Nexus One friendly videos, but can't figure out how to get it to use a specific subtitle track.
If someone can solve one of these for me, I'll be a happy camper.
Well after a lot of googling and trial & error, here is what worked for me:
mencoder infile.mkv -o outfile.mp4 -vf dsize=512:352:2,scale=-8:-8,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -sws 9 -x264encopts nocabac:level_idc=30:bframes=0:bitrate=264:threads=auto:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh
It's not using ffmpeg, but it appears to be working.

Resources