FFmpeg input duration? - ffmpeg

With FFmpeg you have the option -t which will set the duration of the output. However I do not see a way to limit the duration of the input. Take this command
ffmpeg -i video.mp4 -c copy -t 60 out.mp4
This simply creates a 60 second clip of the original video. However if I wanted to clip the audio while keeping the full video stream, FFmpeg does not seem to have an option for this.
I have tried simply clipping the audio first, then combining the clipped audio with the video file, but this causes video/audio sync issues for me.

‘-aframes number (output)’
Set the number of audio frames to record. This is an alias for -frames:a.
§ Audio Options
ffmpeg -i video.mp4 -c copy -aframes 100 out.mp4

Use the "-itsoffset" option.
This makes the first 10 seconds mute.
ffmpeg -i video.mp4 -vn -acodec copy -ss 10.0 out_audio.mp4
ffmpeg -itsoffset 10.0 -i out_audio.mp4 -i video.mp4 -vcodec copy -acodec copy out.mp4

Related

Is there a factor in ffmpeg code that cuts video time?

Im using ffmpeg to change resolution of video file and after conversion to another location the video lasts 0 seconds, but originally it lasts 2mins
My ffmepg code:
ffmpeg -i input.mp4 -filter:v scale=480:320 -t 5 output.mp4
Why are you using the -t modifier? You want to cut the video up? Otherwise, this will convert the whole length to the new quality.
ffmpeg -i input.mp4 -filter:v scale480:320 output.mp4

How do I generate a color screen for the duration of an MP3 in ffmpeg?

I have successfully generated a blue screen to add to an mp3. But, I have always needed to include the length of the clip to match the mp3. When I don't include a timecode it continues to generate footage until I cancel the command.
ffmpeg -f lavfi -i color=blue:s=1920x1080 -i input.mp3 -t 00:02:08 output.mp4
How do I specify that I only want color generated during the length of the mp3 that I am adding?
ffmpeg -i <.jpg> -i <.mp3>
This worked too but I don't want to rely on a jpeg file.
Use -shortest:
ffmpeg -f lavfi -i color=blue:s=1920x1080 -i input.mp3 -shortest output.mp4

How to convert a m3u8 playlist file into a video segment

I've been trying to find out solutions but could not, on how to extract a video segment (say an mp4) from a given m3u8 file, where the video starts from some offset and has a particular duration. Wish someone could help.
I tried this:
ffmpeg -i http://foo.herokuapp.com/input_test.m3u8 -acodec copy -vcodec copy -y -loglevel info -f mp4 myNewVideo.mp4
It generates the video, but now I need it to start from a particular offset and it needs to last a particular duration. I know that the offset might need the -ss flag, but it doesn't seem to be working.
Examples for a capture starting at 30s (-ss) with a duration of 10s (-t).
If the input HLS playlist is of type VOD you can do:
ffmpeg -ss 00:00:30 -i http://foo.herokuapp.com/input_test.m3u8 -t 10 -c copy -bsf:a aac_adtstoasc -flags +global_header -y output.mp4
If the input is a Live stream then:
ffmpeg -i http://foo.herokuapp.com/input_test.m3u8 -ss 00:00:30 -t 10 -c copy -bsf:a aac_adtstoasc -flags +global_header -y output.mp4
The seek is done on the output in the second case (-ss after -i).
You can also add a -re before -i for the live stream if you want to avoid fetching the latest 3 segments at once when you execute the command.

Ffmpeg video overlay

I am trying to create a video output from multiple video cameras.
Following the example given here Presenting more than 2 videos using FFmpeg
and other similar examples.
but Im getting the error
Output pad "default" for the filter "src" of type "buffer" not connected to any destination
when i run
ffmpeg -i /dev/video1 -i /dev/video0 -filter_complex "[0:0]pad=iw*2:ih[a];[a][1:0]overlay=w[b];[b][2:0]overlay=w:h" -shortest output.mp4
Im not really sure what this means or how to fix it.
Any help would be greatly appreciated!
Thanks.
When using the "padding" option, you have to specify which is the size of the output image and where you want to put the input image
[0:0]pad=iw*2:ih:0:0
tested under windows 7 with file of same size
ffmpeg -i out.avi -i out.avi -filter_complex "[0:0]pad=iw*2:ih:0:0[a];[a][1:0]overlay=w" -shortest output.mp4
and with WebCam Cap (vfwcap) and a still picture (as i have only o=1 WebCam). BTW you can see how to scale one the source to fit in the target (just in case your source have different resolution)
ffmpeg -y -f vfwcap -r 10 -i 0 -loop 1 -i photo.jpg -filter_complex "[0:0]pad=iw*2:ih:0:0[a];[1:0]scale=640:480[b];[a][b]overlay=w" -shortest output.mp4
under Linux:
ffmpeg -i /dev/video1 -i /dev/video0 -filter_complex "[0:0]pad=iw*2:ih:0:0[[a];a][1:0]overlay=w" -shortest output.mp4
if it doesn't work test a simple record of video 1 and after of video 0 and check their properties (type, resolution, fps).
ffmpeg -i /dev/video1 -shortest output1.mp4
ffmpeg -I output1.mp4
If you still have issue, update your question with ffmpeg console output (as text) for video and video 0 capture and also of the call with the overlay

ffmpeg -is it possible to increase a clip duration?

I currently have a jpeg file which I converted to an flv using the following command:
ffmpeg -r 10 -b 180000 -i test.jpg test.mp4
Now, I want to increase the duration of this .mp4 clip, so the picture stays on the screen for more than a split second. Eventually, I hope to merge a stream of these files to create a slide show out of jpeg files.
Does anyone know how to increase the duration of a clip in ffmpeg?
Looping the input and setting a duration should achieve the effect you want:
ffmpeg -loop_input -i test.jpg -t 10 test.mp4
Doing something like this should work (at least for a single image):
ffmpeg -loop_input -i picture.jpg -r 1 -vcodec flv -b 192k -i Music.mp3 -acodec copy -shortest output.flv
I bet you could get it working with multiple images by adding more inputs though I haven't tested.
(http://forum.videohelp.com/threads/280695-FFMPEG-Loop-input-video)

Resources