walolinux
walolinux

Reputation: 551

Save .mp4 from YouTube output stream

I am currently running a Ffmpeg script in Raspbian which works fine. It captures video from an USB webcam and stream it to YouTube.

ffmpeg -thread_queue_size 512 -f v4l2 -video_size 1920x1080 -i /dev/video0 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 128k -strict experimental -aspect 16:9 -vcodec h264 -preset veryfast -crf 25 -pix_fmt yuv420p -g 60 -vb 820k -maxrate 820k -bufsize 820k -profile:v baseline -r 30 -f flv rtmp://a.rtmp.youtube.com/live2/XXX-XXX-XXX

But I also want to save the file into an mp4 file.

I have tried adding a .mp4 file to the end, but it generates a corrupt file and the stream does not emit at 1x speed, it get slower to 0.4x

ffmpeg -thread_queue_size 512 -f v4l2 -video_size 1920x1080 -i /dev/video0 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 128k -strict experimental -aspect 16:9 -vcodec h264 -preset veryfast -crf 25 -pix_fmt yuv420p -g 60 -vb 820k -maxrate 820k -bufsize 820k -profile:v baseline -r 30 -f flv rtmp://a.rtmp.youtube.com/live2/XXX-XXX-XXX output.mp4

I have also tried without result:

-vcodec copy -acodev copy output.mp4

Any idea? Thanks.

Upvotes: 0

Views: 928

Answers (1)

Gyan
Gyan

Reputation: 93299

Use

ffmpeg -thread_queue_size 512 -f v4l2 -video_size 1920x1080 -i /dev/video0 -f lavfi -i anullsrc=cl=stereo:r=44100 -map 0:v -map 1:a -r 30 -aspect 16:9 -c:v h264 -preset veryfast -crf 25 -pix_fmt yuv420p -g 60 -maxrate:v 820k -bufsize:v 820k -profile:v baseline -c:a aac -b:a 128k -strict experimental -flags +global_header -f tee "[f=flv]rtmp://a.rtmp.youtube.com/live2/XXX-XXX-XXX|video.flv"

Upvotes: 1

Related Questions