ffmpeg command to merge file with good quality - ffmpeg

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.

Related

Hardcoding subtitles from DVD or VOB file with ffmpeg

I have some DVDs that I would like to encode so that I can play them on a Chromecast, with subtitles. It seems that Chromecast only supports text-based subtitle formats, while DVD subtitles are in a bitmap format, so I need to hardcode the subtitles onto the video stream.
First I use vobcopy to create a VOB file:
vobcopy -I /dev/sr0
Next I want to use ffmpeg to encode it as a video stream in a format that is supported by the Chromecast. This is the closest I've come so far (based on the ffmpeg documentation):
ffmpeg -analyzeduration 100M -probesize 100M -i in.vob \
-filter_complex "[0:v:0][0:s:0]overlay[vid]" -map "[vid]" \
-map 0:3 -codec:v libx264 -crf 20 -codec:a copy out.mkv
The -filter_complex "[0:v:0] [0:s:0]overlay[vid] parameters should overlay the first subtitle stream on the first video stream (-map 0:3 is for the audio). This partially works, but the subtitles are only shown for a fraction of a second (I'm guessing one frame).
How can I make the subtitles display for the correct duration?
I'm using ffmpeg 4.4.1 on Linux, but I've also tried the latest snapshot version, and tried gstreamer and vlc (but didn't get far).
The only solution I found that worked perfectly was a tedious multi-stage process.
Copy the DVD with vobcopy
vobcopy -I /dev/sr0
Extract the subtitles in vobsub format using mencoder. This command will write subs.idx and subs.sub. The idx file can be edited if necessary to tweak the appearance of the subtitles.
mencoder *.vob -nosound -ovc frameno -o /dev/null \
-vobsuboutindex 0 -sid 0 -vobsubout subs
Copy the audio and video from the VOB into an mkv file. ffprobe can be used to identify the relevant video and audio stream numbers.
ffmpeg -fflags genpts -i *vob -map 0:1 -map 0:3 \
-codec:v copy -codec:a copy copied_av.mkv
Merge the subtitles with the audio/video stream.
mkvmerge -o merged.mkv copied_av.mkv subs.sub subs.idx
Then ffmpeg will work reliably with the mkv file to write hardcoded subtitles to the video stream.
ffmpeg -i merged.mkv -filter_complex "[0:v:0][0:s:0]overlay[vid]" \
-map [vid] -map 0:1 -codec:v libx264 -codec:a copy hardcoded.mkv

Converting a large number of MP3 files to videos for YouTube, each using same the JPEG image

I am looking for a way to convert large number of MP3 files to videos, each using the same image. Efficient processing time is important.
I tried the following:
ffmpeg -i image.jpg -i audio.mp3 -vcodec libx264 video.mp4
VLC media player played the resulting video file with the correct sound, but a blank screen.
Microsoft Media Player played the sound and showed the intended image. I uploaded the video to YouTube and received the message:
"The video has failed to process. Please make sure you are uploading a supported file type."
How can I make this work?
Create video:
ffmpeg -framerate 6 -loop 1 -i input.jpg -c:v libx264 -vf format=yuv420p -t 00:10:00 video.mp4
The duration (-t) should be ≥ the MP3 with the longest duration.
Now stream copy the same video for each MP3:
ffmpeg -i video.mp4 -i audio.mp3 -map 0:v -map 1:a -c copy -movflags +faststart -shortest output.mp4
Some notes regarding compatibility:
MP3 in MP4 does not have universal support, but will be fine in YouTube. If your target players do not like it then add -c:a aac after -c copy to output AAC audio.
If your target player does not like it then increase the -framerate value or add the -r output option with an appropriate value, such as -r 15. Again, YouTube should be able to handle it.

ffmpeg audio property is blank in output video

Here's what I have to do,
I want to convert two different images in different video file (ex: convert a.jpg into a.avi and b.jpg into b.avi).
I am trying to generate video (.avi) from image file. Video file is generated successfully but I can't see the audio properties when I right click on video and see details tab in property.
Then I have one video file (.avi), using ffmpeg concat function, I am concating these three video files (a.avi, middle.avi which I already have, b.avi).
After this, I am getting file output.avi but audio is not there in outout.avi file. I have middle.avi which already contains audio.
Here's my concat command,
ffmpeg -i "concat:a.avi|middle.avi|b.avi" -vcodec copy 103_n4_2.avi
I am trying to generate video (.avi) from only one image file. Video file is generated successfully but I can't see the audio properties when I right click on video and see details tab in property.
Here's my command to convert image to video:
ffmpeg -loop 1 -i bCopy.jpg -t 30 -q:v 0 -r 24 output_a.avi
PS: a.avi and b.avi (which I have generated from images does not contain audio) but only middle.avi contains the audio.
I think the audio track is completly ommitted. I was not able to test it but it seams you need to map the audio stream manually to the output and delay it by the the length of your first image.
ffmpeg -i middle.avi -itsoffset 1 -map 1:1 -i "concat:a.avi|middle.avi|b.avi" -map 0:0 -vcodec copy -acodec copy 103_n4_2.avi
Thanks for the help but I have found the solution of this perticular issue,
Here are the steps:
1. Generate blank mp3 of the first slide duration.
- ffmpeg -f lavfi -i aevalsrc=0 -t 31 -q:a 9 -acodec libmp3lame out.mp3
2. Trim audio from middle slide
- ffmpeg -i middle.avi -acodec copy middle.mp3
3. Concat this two audio
- ffmpeg -i "concat:out.mp3|middle.mp3" -acodec copy 103_n4_2.mp3
4. Now concat audio and video(that we've cgenerated by concatenation)
- ffmpeg -i 103_n4_3.avi -i 103_n4_2.mp3 -c:v copy -c:a aac -strict experimental 103_n4_5.avi

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 write a filter for ffmpeg that burn subtitles using a subtitle stream directly

Let say I have an MKV with a video stream, an audio stream and a subtitles stream.
I would like to burn this subtitle into my video directly from the subtitle stream.
so far, this is my command line :
ffmpeg.exe -i "MyMovie.mkv" -map 0:0 -map 0:1 -vf subtitles=sub.srt out.mkv
So far so good. But, my subtitles are inside the movie and I need to extract them before. I used this :
ffmpeg.exe -i "MyMovie.mkv" -f srt sub.srt
But this operation is too long : ~25 sec on my PC for a 2.5Go MKV. I need something faster because I need to start streaming the output to an app as soon as possible. (I did not mentioned the others command line arguments I used to achieve this streaming properly because my question is not about that.)
I know it is not possible to get the stream directly like this :
ffmpeg.exe -i "MyMovie.mkv" -map 0:0 -map 0:1 -vf subtitles=[0:s:0] out.mkv
But this is something I would love.
edit :
But I already know this kind of command line do not exist. (But if I'm wrong, please, let me know.)
Now, I would like to write this kind of filter myself, and compile ffmpeg with it.
But I have no idea where to start.
Can anyone help me to start ?
Thank you
your are looking for the "picture based" mode
ffmpeg -i input.mkv -filter_complex "[0:v][0:s]overlay[v]" -map [v] -map 0:a <output options> output.mkv
here we map the 1st(0:s) subtitle stream on the 1st video(0:v)
described with more details here

Resources