Combine video segments and stream with ffmpeg - ffmpeg

FFmpeg can save a video stream to disc as video segments with the following command (source)
ffmpeg -rtsp_transport tcp -reorder_queue_size 8000 -i rtsp://192.168.10.203:554/11 -r 25 -vcodec copy -acodec copy -map 0 -f segment -segment_time 60 -reset_timestamps 1 -segment_format avi "/vidcam2cont/ffmpeg_capture-%03d.avi"
Is there a way to achieve the reverse of this (using FFmpeg or anything else), where I want to merge the video segments and get a continuous video stream?

Related

FFmpeg streaming rtmp muliple streams

I have a mpeg file with two video streams stream
#0:0[0x27] yuv420p 352X288
and
#0:1[0x29] yuv420p 640X480
I am trying to read the file and send it out rtmp
ffmpeg -stream_loop -1 -i myvideofile.mpg -f mpegts udp://localhost:123456
To verify the stream is streaming I use ffplay
ffplay udp://localhost:123456
I get the video, but it is only one of the two streams I am expecting. the 640x480
Is there something that I need to do to make both streams get sent?
To remap all streams you have to pass -map 0.
ffmpeg -stream_loop -1 -i myvideofile.mpg -map 0 -f mpegts udp://localhost:123456

Convert mp4 video with joining animation mp4 + audio(wav, mp3) using ffmpeg shell command

I want to create .mp4 video by joining short animation(.mp4) + audio(wav, mp3) using ffmpeg shell command.
I have tried few commands to join mp4 + audio here is my example command which will generate output video.
./ffmpeg -y -i ./output/preview-2.mp4 -i ./output/audio-file.mp3 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -r 25 -vcodec libx264 -pix_fmt yuv420p ./output/converted-video.mp4
But I want to play my animation till audio playing. The above FFMPEG command only join my animation(short video .mp4) file with audio and stopped animation playing after duration of short video reached to end (let's say animation file duration is 10seconds and stopped playing after 10 seconds). But my audio is about 3 minutes and I want to re-play the animation video again and again till the audio file duration (3 minutes). Just like a looping effect.
Add -stream_loop -1 and -shortest:
./ffmpeg -y -stream_loop -1 -i ./output/preview-2.mp4 -i ./output/audio-file.mp3 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -r 25 -vcodec libx264 -pix_fmt yuv420p -shortest ./output/converted-video.mp4

FFMPEG reduce fps for live h264 stream with direct copy

I found different articles on changing the fps with ffmpeg but none of them is matching for my exact purposes.
There is an ffmpeg command like below:
ffmpeg -i RTSPCAMERAPRODUCEH264 -c:v copy -an -movflags +frag_keyframe+empty_moov -f mp4
This will remux my camerastream to fragmented mp4 perfectly.
Is there a way to force ffmpeg to lower the FPS to save bandwidth?
I.e. camera streams 30fps, it needs 1Mbps for fmp4 (sample numbers!):
I'd like to know if it's possible to lower the FPS and get an output stream for which 500kbps (50% of original is enough) without re-encoding.
ffmpeg -r 1 -i RTSPCAMERAPRODUCEH264 -c:v copy -an -movflags +frag_keyframe+empty_moov -f mp4
and
ffmpeg -i RTSPCAMERAPRODUCEH264 -c:v copy -an -movflags +frag_keyframe+empty_moov -r 1 -f mp4
do not seem to work.
A temporally coded video stream (like one with H264 codec) cannot arbitrarily drop intermediate packets, so this is not possible. Only whole or trailing part of GOPs may be dropped.

FFMPEG: Add FrameRate Option Seconds Stream

I am trying to Copy Two H264 stream into One MP4 File. But I want to set the Framerate for Both H264 stream before copying into One MP4 File. I am able to set FrameRate for First Video H264 Stream. But not able to able to set FrameRate for Seconds Video H264 Stream.
Here are my attempts.
ffmpeg -r:v:0 15 -i 15FPS.h264 -r:v:1 30 -i 30FPS.h264 -c:v:0 copy -c:v:1 copy -map 0 -map 1 hello.mp4
ffmpeg -r:v:0 15 -i 15FPS.h264 -r:v:1 30 -i 30FPS.h264 -c copy -map 0 -map 1 hello.mp4
First H264 Stream in MP4 File is with 15 FPS but For Second Stream FFMPEG takes by default FPS setting with 25 even I specified 30 explicitly.
Can Someone Point me which part is wrong in my command. It would be appreciated.
Your 2nd stream specifier is wrong. It should also be -r:v:0 since -r is a per-file option and raw .h264 can contain only one stream. (So you can drop the specifier altogether)
ffmpeg -r 15 -i 15FPS.h264 -r 30 -i 30FPS.h264 -c copy -map 0 -map 1 hello.mp4

Mix audio/video of different lengths with ffmpeg

I want to mix video from video.mp4 (1 minute duration) and audio from audio.mp3 (10 minute duration) into one output file with a duration of 1 minute. The audio from audio.mp3 should be from the 4 min - 5 min position. How can I do this with ffmpeg?
If video.mp4 has no audio
You can use this command:
ffmpeg -i video.mp4 -ss 00:04:00 -i audio.mp3 -c copy -shortest output.mkv
The audio will be from the 4 minute position (-ss 00:04:00) as requested in the question.
This example will stream copy (re-mux) the video and audio–no re-encoding will happen.
If video.mp4 has audio
You will have to add the -map option as described here: FFmpeg mux video and audio (from another video) - mapping issue.
If the audio is shorter than the video
Add the apad filter to add silent padding:
ffmpeg -i video.mp4 -ss 00:04:00 -i audio.mp3 -c:v copy -af apad -shortest output.mkv
Note that filtering requires re-encoding, so the audio will be re-encoded in this example.

Resources