I have written a small piece of code to re-stream camera RTSP stream on Nginx stream server using FFMPEG.
Everything working fine, my re-stream RTSP on to Nginx stream server using following FFMPEG command:
ffmpeg -rtsp_transport tcp -i 'rtsp://212.78.10.88:554/stream' -f lavfi -i aevalsrc=0 -vcodec copy -acodec aac -map 0:0 -map 1:0 -shortest -strict experimental -f flv rtmp://localhost:1935/live/stream
My basic problem is H265 and H265+. FFMPEG failed to re-stream H265 format streams. I tried differently command params but no luck.
Any body know how to re-stream H265 and + in FFMPEG?
Finally, I solved the issue to re-stream h265 stream.
I just used following arguments in command to solve this issue.
-c:v libx264 -pix_fmt yuv420p
and final command is:
ffmpeg -rtsp_transport tcp -i 'rtsp://212.78.10.88:554/stream' -f lavfi -i aevalsrc=0 -vcodec copy -acodec aac -map 0:0 -map 1:0 -c:v libx264 -pix_fmt yuv420p -shortest -strict experimental -f flv rtmp://localhost:1935/live/stream
Related
I tried to stream an mp3 file to a Telegram RTMP live using the following command:
ffmpeg -re -i 1.mp3 -c copy -f mp3 rtmps://dc4-1.rtmp.t.me/s/145158:AtyF3rrME2nHEkqGA
But I couldn't hear any sound in the stream.
You should specify the codecs explicitly.
The following is the simplest working command:
ffmpeg -i your_input -c:v libx264 -c:a aac -f flv rtmps://dcx-y.rtmp.t.me/s/YOUR_KEY
Here is a more advanced example from #tgbeta:
ffmpeg -stream_loop -1 -re -i your_input -c:v libx264 -preset veryfast -b:v 3500k -maxrate 3500k -bufsize 7000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmps://dcx-y.rtmp.t.me/s/YOUR_KEY
Change -f mp3 by -f flv.
Example:
ffmpeg -re -i 1.mp3 -c:a copy -f flv rtmps://dc4-1.rtmp.t.me/s/145158:AtyF3rrME2nHEkqGA
I am trying to convert H265 rtsp stream to H264.
ffmpeg -rtsp_transport tcp -i 'rtsp://admin:admin123#192.168.1.42:554/stream2' -f lavfi -i aevalsrc=0 -vcodec copy -acodec aac -map 0:0 -map 1:0 -c:v libx264 -pix_fmt yuv420p -shortest -strict experimental -f flv rtmp://localhost:1935/live/stream
When I use this command it gives this error.
[tcp # 0x23f13b0] Connection to tcp://localhost:1935 failed: Connection refused
[rtmp # 0x23f1270] Cannot open connection tcp://localhost:1935
rtmp://localhost:1935/live/stream: Connection refused
If FFmpeg should act as a server you must add the parameter -listen 1.
ffmpeg -i 'rtsp://admin:admin123#192.168.1.42:554/stream2' {...} -f flv -listen 1 rtmp://localhost:1935/live/stream
I'm trying to change FFMPEG encoder writing application with FFMPEG -metadata and for whatever reason, it's reading the input but not actually writing anything out.
-map_metadata -metadata:s:v:0 -metadata writing_application, basically every single stack overflow and stack exchange thread, but they all won't write to the file at all.
ffmpeg -i x.mp4 -s 1920x1080 -r 59.94 -c:v h264_nvenc -b:v 6000k -vf yadif=1 -preset fast -fflags +bitexact -flags:v +bitexact -flags:a +bitexact -ac 2 x.mp4
ffmpeg -i x.mp4 -c:v copy -c:a copy -metadata Encoder="TeXT Encoder" -fflags +bitexact -flags:v +bitexact -flags:a +bitexact test.mp4
ffmpeg -i x.mp4 -vcodec copy -acodec copy -map_metadata out.mp4
ffmpeg -i x.mp4 -vcodec copy -acodec copy -metadata encoder="Encoder" -metadata comment="XX" testmeta.mp4
ffmpeg -i x.ts -c:v copy -c:a copy -metadata:s:v:0 h264 ISFT='TeXT' x.mp4
ffmpeg -i x.mp4 -i FFMETADATAFILE -map_metadata 1 -codec copy testcopy.mp4
ffmpeg -i x.ts -f ffmetadata FF
METADATAFILE
I tried to extracting the data and rewrite it back with FFMETADATAFILE but it doesn't show up. Tried forcing ffmpeg to write without any emtadata and write it back but doesn't work. Was wondering if I can write my own encoder that writes the specific encoder name, like how Handbrake/Lavf writes the encoder application into the METADATA of the video file. Or just use FFMPEG and modify the METADATA natively.
To set the writing application (mediainfo) or encoder (ffmpeg) for MP4s, use
ffmpeg -i input {-encoding parameters} -metadata:g encoding_tool=myapp out.mp4
I am trying to create a video composed of clips of images and videos. For the clips of images, I use ffmpeg to create a video file and then I add a silent audio stream through these two steps:
ffmpeg.exe -loop 1 -i MyImage.png -codec:v libx264 -t 4.0 -profile:v high -preset slow -r 25 -b:v 500k -maxrate 500k -pix_fmt yuv420p -vf scale=1280:720 MyImageMovie.mp4
ffmpeg.exe -f lavfi -i anullsrc=r=48000 -i MyImageMovie.mp4 -shortest -c:v copy -c:a aac -strict experimental -y MyImageMovieWithSilentAudioStream.mp4
Then I combine my video clips and image clips with
ffmpeg.exe -f concat -i videoList.txt -c copy -y concatVideo.mp4
At this point, the video looks good, any video clips that have audio streams seemed well synced to the video.
Now I add a soundtrack:
ffmpeg.exe -i concatVideo.mp4 -i soundtrack.mp3 -ar 48000 -filter_complex "[1:a]apad [b] ; [0:a][b]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -ac 2 -shortest -y FinalVideo.mp4
The problem is that the soundtrack on FinalVideo.mp4 stutters at some (not all) of the concatenation joints.
I suspect it has to do with the audio stream and the video stream of the Image clips not being perfectly aligned. The aac has .0231s resolution and the video has 0.04s resolution. When I ffprobe the MyImageMovieWithSilentAudioStream.mp4 the duration is 4.00s but the start is 0.0213.
If my concatenated video has several of these image clips, the error can start to accumulate.
What can I do to keep the video and audio in sync and add a soundtrack that doesn't stutter?
Also, this is a little interesting, I don't hear the stutter when the final video is played on Windows Media Player, but it is there if I play it on VLC or via the html native video element.
Try adding the soundtrack in the same step as the concat.
ffmpeg -f concat -i videoList.txt -i soundtrack.mp3 \
-filter_complex "[1:a]apad[b];[0:a][b]amerge=inputs=2[a]" \
-map 0:v -map "[a]"
-c:v copy -c:a aac -ac 2 -ar 48000 -shortest -y FinalVideo.mp4
As an aside, you can also combine the image and silent stream generation,
ffmpeg -loop 1 -i MyImage.png -f lavfi -i anullsrc=r=48000 \
-vf scale=1280:720 \
-c:v libx264 -profile:v high -preset slow -r 25 -b:v 500k -maxrate 500k -pix_fmt yuv420p \
-c:a aac -strict experimental -t 4 -y MyImageMovieWithSilentAudioStream.mp4
I have a trouble with ffmpeg
I receive a rtsp stream from a grabbing device (camera) and I stream-out it to rtmp (Youtube Live)
I want to have a copy of the stream in my computer so I write at the same time in a local file
I use this command :
ffmpeg -y -i 'RTSP_SOURCE' -c:v copy -c:a libvo_aacenc -map 0:v -bsf:v dump_extra -fflags +genpts -flags +global_header -movflags +faststart
-map_metadata 0 -metadata title= -f tee -filter_complex aevalsrc=0 '[f=mp4]/tmp/backup.mp4|[f=mpegts]/tmp/backup.ts|[f=flv]rtmp://a.rtmp.youtube.com/live2/STREAM_ID'
The problem is when I have some disconnections, ffmpeg exits and stop to recording
Is there any flag or option for telling to ffmpeg to continue recording in local files even there is not internet ?
Thank you very much for your help =)
You can try:
ffmpeg -f tee "[onfail=ignore] ...
More description is available here.