Mencoder - Audio is longer than Video Stream - audio

I am trying use some images and audio to create video using mencoder.
But my audio file could be much longer.
Example:
5 images.
fps: 1
desired video length: 5 seconds
audio file length is: 20 seconds.
mencoder mf://*.jpg -mf fps:1.0 -oac mp3lame -audiofile myaudio.mp3 -ovc lavc vcodec=mpeg4 -o myvideo.mpeg
This produces a video that is:
20 seconds long (as long as audio file length).
The image slide show ends at 5 seconds, after that there is only audio playing (from 6th to 20th second).
How can i make mencoder to generate video of only duration where video stream exists. In this case end the video at 5 seconds.
ffmpeg has a -shortest option for exactly this kind of use case. But i cannot find equivalent of that in mencoder.

Related

Synchronize + merge audio of one video file into another

Suppose the following:
I got two video files with audio
They are pretty much the same (going by 'images'), but differ in codec, quality, .. and audio.
To have a more specific example, furtermore suppose:
Video 1 (the 'target') is running #24 FPS in 2160p [HEVC]. The first 25 seconds of audio and video are not "belonging"/unessential to the video depicted.
Video 2 is running #30 FPS in 720p [X264]. The first 19 seconds of audio and video are not "belonging"/unessential to the video depicted.
I now want to perfectly merge the audio of "Video 2" into the target Video, so that the audio of both videos pretty match (except e.g. language)
My initial thought would be to synchronize both videos by frames using fingerprinting/hashes similar to various repost checker bots.
Is there an easier method, how would I go from there (preferably using ffmpeg)?
Bonus points if the first 25 seconds of the "Video 1" audio are prepended to the "Video 2" audio while the first 19 seconds are omitted.

Output a new mp3 file from a lengthy mp3 mix which previews the audio at 5 different points of the mix

I basically have a large collection of audio mix files in mp3 format, say approx 2 hours worth of music per mp3.
I am trying to work out the best way using the command line to output a preview MP3 file, this mp3 should have 5-10 second previews of the full mix at 6 or so points during the mix.
Example
00:00:10 - 00:00:20
00:30:00 - 00:30:10
00:50:00 - 00:50:10
...
So with the small mp3 file, you can kind of get an idea of the whole mix in a very short preview.
I have seen ffmpeg etc that can preview say 5 seconds up to 15 seconds of an audio, but not sure if this is capable of doing multiple points of the audio.
Any ideas or help is appreciated.
Use the aselect filter in ffmpeg.
ffmpeg -i in.mp3 -af aselect='between(t\,10\,20)+between(t\,1800\,1810)+between(t\,3000\,3010)' -c:v copy preview.mp3
Each between block selects a time range. Times are expressed in seconds.

FFMPEG:Adding beep sound to another audio file in specific time portions

I've a scenario in which I need to modify certain portions of audio file.Currently,I'm able to add silence to the audio file at specific portions through FFMPEG audio filter -af.But is there something that can replace particular portions of audio with beep sound and the duration of the file should be same after the process?
Eg: Input.wav,I want to add beep of 10s-15s(i.e.,5 seconds) to the file
Replace audio with beep from 10 to 15 seconds:
ffmpeg -i input.wav -filter_complex "[0]volume=0:enable='between(t,10,15)'[main];sine=d=5:f=800,adelay=10s,pan=stereo|FL=c0|FR=c0[beep];[main][beep]amix=inputs=2" output.wav
sine - makes beep sound
adelay - adds a delay to position the beep
pan - one of many methods to convert the beep from mono to stereo
amix - mixes the beep into the main audio
If the beep occurs almost immediately at 10 milliseconds instead of at 10 seconds then your ffmpeg is old and you have to declare milliseconds instead of seconds: adelay=10000.

mkv file out of sync with linear drift

I have a bunch of mkv files, with FLAC as the audio codec and FFV1 as the video one.
The files were created using an EasyCap aquisition dongle from a VCR analog source. Specifically, I used VLC's "open acquisition device" prompt and selected PAL. Then, I converted the files (audio PCM, video raw YUV) to (FLAC, FFV1) using
ffmpeg.exe -i input.avi -acodec flac -vcodec ffv1 -level 3 -threads 4 -coder 1 -context 1 -g 1 -slices 24 -slicecrc 1 output.mkv
Now, the files are progressively out of sync. It may be due to the fact that while (maybe) the video has a constant framerate, the FLAC track has variable framerate. So, is there a way to sync the track to audio, or something alike? Can FFmpeg do this? Thanks
EDIT
On Mulvya hint, I plotted the difference in sync at various times; the first column shows the seconds elapsed, the second shows the difference - in secs. The plot seems to behave linearly, with 0.0078 as a constant slope. NOTE: measurements taken by hands, by means of a chronometer
EDIT 2
Playing around with VirtualDub, I found that changing the framerate to 25 fps from the original 24.889 (Video->Frame rate...->Change frame rate to) and using the track converted to wav definitely does work. Two problems, though: VirtualDub crashes when importing the original FFV1-FLAC mkv file, so I had to convert the video to H264 to try it out; more, I find it difficult to use an external encoder to save VirtualDub output.
So, could I avoid using VirtualDub, and simply use ffmpeg for it? Here's the exported vdscript:
VirtualDub.audio.SetSource("E:\\4_track2.wav", "");
VirtualDub.audio.SetMode(0);
VirtualDub.audio.SetInterleave(1,500,1,0,0);
VirtualDub.audio.SetClipMode(1,1);
VirtualDub.audio.SetEditMode(1);
VirtualDub.audio.SetConversion(0,0,0,0,0);
VirtualDub.audio.SetVolume();
VirtualDub.audio.SetCompression();
VirtualDub.audio.EnableFilterGraph(0);
VirtualDub.video.SetInputFormat(0);
VirtualDub.video.SetOutputFormat(7);
VirtualDub.video.SetMode(3);
VirtualDub.video.SetSmartRendering(0);
VirtualDub.video.SetPreserveEmptyFrames(0);
VirtualDub.video.SetFrameRate2(25,1,1);
VirtualDub.video.SetIVTC(0, 0, 0, 0);
VirtualDub.video.SetCompression();
VirtualDub.video.filters.Clear();
VirtualDub.audio.filters.Clear();
The first line imports the wav-converted audio track.
Can I set an equivalent pipe in ffmpeg (possibly, using FLAC - not wav)? SetFrameRate2 is maybe the key, here.

ffmpeg split avi into frames with known frame rate

I posted this as comments under this related thread. However, they seem to have gone unnoticed =(
I've used
ffmpeg -i myfile.avi -f image2 image-%05d.bmp
to split myfile.avi into frames stored as .bmp files. It seemed to work except not quite. When recording my video, I recorded at a rate of 1000fps and the video turned out to be 2min29sec long. If my math is correct, that should amount to a total of 149,000 frames for the entire video. However, when I ran
ffmpeg -i myfile.avi -f image2 image-%05d.bmp
I only obtained 4472 files. How can I get the original 149k frames?
I also tried to convert the frame rate of my original AVI to 1000fps by doing
ffmpeg -i myfile.avi -r 1000 otherfile.avi
but this didn't seem to fix my concern.
ffmpeg -i myfile.avi -r 1000 -f image2 image-%07d.png
I am not sure outputting 150k bmp files will be a good idea. Perhaps png is good enough?
Part one of your math is good, the 2 minutes and 29 seconds is about 149 seconds. With 1000 fps that makes 149000 frames. However your output filename only has 5 positions for the number where 149000 has 6 positions, so try "image-%06d.bmp".
Then there is the disk size: Do your images fit on the disk? With bmp every image uses its own size. You might try to use jpeg pictures, they compress about 10 times better.
Another idea: If ffmpeg does not find a (reasonable) frame rate, it drops to 25 or 30 frames per second. You might need to specify it. Do so for both source and target, see the man page (man ffmpeg on unix):
To force the frame rate of the input file (valid for raw formats
only) to 1 fps and the frame rate of the output file to 24 fps:
ffmpeg -r 1 -i input.m2v -r 24 output.avi
For what it's worth: I use ffmpeg -y -i "video.mpg" -sameq "video.%04d.jpg" to split my video to pictures. The -sameq is to force the jpeg in a reasonable quality, the -y is to avoid allow overwrite questions. For you:
ffmpeg -y -r 1000 -i "myfile.avi" -sameq "image.%06d.jpg"
I think, there is a misconception here: the output of a HS video system is unlikely to have an output frame rate of 1000 fps but something rather normal as 30 (or 50/60) fps. Apart from overloading most video players with this kind of speed it would be counterproductive to show the sequence in the same speed as it was recorded.
Basically: 1 sec # 1000 fps input is something like 33 sec # 30 fps output.
Was the duration of the scene recorded really 2:29 min (resulting in a video ~82 min at normal rate) or took it about 4.5 sec (4472 frames) which is 2:29 min in normal playback?
I tried this on ubuntu 18.04 terminal.
ffmpeg -i input_video.avi output_frame_path_images%5d.png
where,
-i = Input

Resources