FFMPEG Combining images to video and streaming in one command line - linux

Currently, using ffmpeg, I am using two commands on my Terminal to:
1) create a video from a bunch of images:
ffmpeg -r 60 -f image2 -s 1920x1080 -i rotated-pano_frame%05d_color_corrected_gradblend.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4
2) stream the video to a udp address:
ffmpeg -re -i test.mp4 -c copy -f flv udp://127.0.0.1:48550
How can I combine these two commands, into one single ffmpeg command?
A concern I have is that it takes a couple of minutes to generate the video from the images. Therefore, these commands have to happen serially, whereby the second command waits a few minutes for the first command to be completed, before it ensues.

Just add && between the two commands. This will execute the second command if the first executes successfully.
ffmpeg -r 60 -f image2 -s 1920x1080 -i rotated-pano_frame%05d_color_corrected_gradblend.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4 && ffmpeg -re -i test.mp4 -c copy -f flv udp://127.0.0.1:48550

Related

ffmpeg: Generate empty audio and video (working for video)

I'm trying to generate a black video with FFMPEG. I have accomplished this with the following:
ffmpeg -t 5 -f lavfi -i color=c=black:s=1920x1080 -c:v libx264 -tune stillimage -pix_fmt yuv420p out.mp4
Unfortunately this video doesn't have any audio tracks. Following this, I have tried to insert -i anullsrc=channel_layout=stereo:sample_rate=44100:
ffmpeg -t 5 -i anullsrc=channel_layout=stereo:sample_rate=44100 -f lavfi -i color=c=black:s=1920x1080 -c:v libx264 -tune stillimage -pix_fmt yuv420p out.mp4
Unfortunately this gives the error:
anullsrc=channel_layout=stereo:sample_rate=44100: No such file or
directory
How can I modify my initial script to generate a video with empty audio?
anullsrc is also a source filter so it too needs -f lavfi before it.
ffmpeg -f lavfi -t 5 -i color=c=black:s=1920x1080 -f lavfi -t 5 -i anullsrc=channel_layout=stereo:sample_rate=44100 -c:v libx264 -tune stillimage -pix_fmt yuv420p out.mp4

Ffmpeg script cuts out sound

I have this ffmpeg script I'm running to automatically convert videos to instagram's accepted coded
The script looks like this:
ffmpeg -analyzeduration 20M -probesize 20M -y -re -f lavfi -i "movie=filename='file.mp4':loop=5, setpts=N/(FRAME_RATE*TB)" -vcodec libx264 -b:v 3500k -vsync 2 -t 59 -acodec aac -b:a 128k -pix_fmt yuv420p -vf "scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:white" -crf 24 new_file.mp4
However that seems to cut out the audio, and I can't seem to find out how to prevent that? I didn't use any -an or anything, and when messing around the audio keeps being cut out? Any idea why?
The movie filter, by default, only reads one video stream from the input.
For looping, stream_loop is available without having to use filters.
ffmpeg -analyseduration 20M -probesize 20M -y -re -stream_loop 5 -i "file.mp4" -vcodec libx264 -b:v 3500k -vsync cfr -t 59 -acodec aac -b:a 128k -pix_fmt yuv420p -vf "scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:white" -crf 24 new_file.mp4

FFmpeg (merge two audio)

I have two long audio files. I want to merge cut some part from each video
and merge both parts in one file.
In below command the problem there is no audio in the second audio part. It contain the first part and the second is empty.
What is the problem?
ffmpeg -f lavfi -i color=c=black
-ss 157.824 -t 99.818
-i "file1.mp4"
-ss 315.764 -t 50.308
-i "file2.mp4"
-s 854x480
-aspect 1.779167
-r 25
-c:v libx264
-b:v 800k
-c:a aac
-strict experimental
-b:a 128k
-f mp4
-t 150.126 -async 1
-y "output.mp4"

Creating Video and Streaming Command Line

Currently, using ffmpeg, I am using two commands on my Terminal to:
1) create a video from a bunch of images:
ffmpeg -r 60 -f image2 -s 1920x1080 -i rotated-pano_frame%05d_color_corrected_gradblend.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4
2) stream the video to a udp address:
ffmpeg -re -i test.mp4 -c copy -f flv udp://127.0.0.1:48550
I am trying to combine both these instructions into one command line instruction, using &&, as suggested in the answer to a previous question of mine:
ffmpeg -r 60 -f image2 -s 1920x1080 -i rotated-pano_frame%05d_color_corrected_gradblend.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4 \
&& ffmpeg -re -i test.mp4 -c copy -f flv udp://127.0.0.1:48550
but am encountering an error which prevents streaming:
[flv # 0x7fa2ba800000] video stream discovered after head already parsed.
Thoughts on a different command line syntax to join the two instructions, different ffmpeg instruction (filters perhaps?), and why I am getting the error?

ffmpeg audio and video sync error

./ffmpeg \
-f alsa -async 1 -ac 2 -i hw:2,0 \
-f video4linux2 -vsync 1 -s:v vga -i /dev/video0 \
-acodec aac -b:a 40k \
-r 25 -s:v vga -vcodec libx264 -strict -2 -crf 25 -preset fast -b:v 320K -pass 1 \
-f flv rtmp://192.168.2.105/live/testing
with the above command i able to stream with fps of 25 but their is no audio and video synchronization i.e., audio is faster than video,i am using ffmpeg 0.11.1 version on the pandaboard for an rtmp streaming ,help me out to solve this problem.
Thanks
Ameeth
Don't use -pass 1 if you're not actually doing two-pass encoding.
From the docs (emphasis added):
‘-pass[:stream_specifier] n (output,per-stream)’
Select the pass number (1 or 2). It is used to do two-pass video encoding. The statistics of the video are recorded in the first pass into a log file (see also the option -passlogfile), and in the second pass that log file is used to generate the video at the exact requested bitrate. On pass 1, you may just deactivate audio and set output to null, examples for Windows and Unix:
ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y NUL
ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y /dev/null
I was streaming to Twitch, and, funnily enough, removing the -r option made video sync with the audio. Now, you might want to have the framerate limited in some way; unfortunately, I have no solution for that, but it does allow to sync the video with the audio very well.

Resources