ffmpeg -rtsp_transport tcp -i "rtsp://.............." -re -stream_loop -1 -i audio.m4a -filter_complex "[0:a]highpass=f=200,lowpass=f=3000,volume=0.3[mic];[1:a]volume=0.1[mic2];[mic][mic2]amix=duration=shortest[a]" -map 0:v -map "[a]" -c:v copy -b:a 320k -c:a aac -f flv "rtmp://......."
This is my working very well script thanks to #Ilogan
But now i have a problem with an audio out of sync, i don't care about the second one, its just a file audio but the first one is from a microphone of camera IP so it should be synced with the video but now the sound from a microphone is almost 28 seconds later.
Any tips how to do it?
adelay=28000 ? - nope, that didnt help since i need to delay the video to sync this with an audio.Also tried -use_wallclock_as_timestamps 1 but it didnt help neither.
Also i used -itsoffset 28 it helped but for a while, looks like that the delay time between video and audio is rising and now its 40sec+
Whats going on?
Now i'm trying with tpad=start_duration=28
edit:
Metadata:
title : NVT
comment : From NVT
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264 (High), yuvj420p(pc, progressive), 1920x1080, 5 fps, 30 tbr, 90k tbn, 10 tbc
Stream #0:1: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s
Stream #0:2: Data: none
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'audio.m4a':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
title : Nature
artist :
date : 2018
encoder : Lavf58.20.100
comment :
Duration: 08:20:49.15, start: 0.000000, bitrate: 129 kb/s
Stream #1:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 01/28/2020.
Stream mapping:
Stream #0:1 (pcm_mulaw) -> highpass
Stream #1:0 (aac) -> volume
Stream #0:0 -> #0:0 (copy)
amix -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[rtsp # 0x82e490] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Output #0, flv, to 'rtmp://....':
Metadata:
title : NVT
comment : From NVT
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), yuvj420p(pc, progressive), 1920x1080, q=2-31, 5 fps, 30 tbr, 1k tbn, 90k tbc
Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
encoder : Lavc58.35.100 aac
frame= 7 fps=0.0 q=-1.0 size= 572kB time=00:00:00.44 bitrate=10634.7kbitsframe= 13 fps= 13 q=-1.0 size= 697kB time=00:00:00.88 bitrate=6463.4kbits/frame= 25 fps= 16 q=-1.0 size= 1185kB time=00:00:01.48 bitrate=6533.1kbits/frame= 33 fps= 16 q=-1.0 size= 1390kB time=00:00:01.99 bitrate=5702.1kbits```
Related
I have a video that already contains an audio stream. I'm trying to add a second audio stream to that same video.
ffmpeg -i input1.mkv -i input2.mp3 -map 0 -map 1:a -c:v copy output.mp4
This seems very straightforward. But when I try to play the video, I can only hear one of the audio streams. This happens even if I reverse the order of the inputs, and regardless of whether I output to an mp4 or mkv file. It also happens if I map all of the streams from all of the input using -map 0 and -map 1, and it still persists if I use a wav file for the second input instead of an mp3
When I use ffprobe to examine the output video, it's clear that there are three streams:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.27.100
Duration: 00:05:05.09, start: 0.000000, bitrate: 9973 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 3840x2160 [SAR 3:4 DAR 4:3], 11272 kb/s, 27.28 fps, 24 tbr, 16k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 131 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
How do I get this video to play both of the audio streams? This seems so simple, and it's driving me crazy that I can't figure it out.
I've got a video which looks and sounds right when I play it in Windows or on a Mac.
I trimmed it with ffmpeg.
The resulting file
plays fine on a Mac with QuickTime
throws an error on Windows QuickTime (Error -2041: an invalid sample description was found in the movie (myfile.trimmed.mp4))
plays with Win10's default player (Movies and TV?), but with the audio lagging nearly 3 seconds behind the video (as determined by me counting Mississippis, nothing more precise than that.)
My original file:
ffprobe -hide_banner myfile.mpg
[h264 # 00000253d2d762c0] Increasing reorder buffer to 2
[mpegts # 00000253d2d6fe00] PES packet size mismatch
[mpegts # 00000253d2d6fe00] Packet corrupt (stream = 1, dts = 8467425232).
[mpegts # 00000253d2d6fe00] Could not find codec parameters for stream 2 (Unknown: none ([151][0][0][0] / 0x0097)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'myfile.mpg':
Duration: 00:30:00.63, start: 92282.982578, bitrate: 6249 kb/s
Program 1
Stream #0:0[0x1aab]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
Stream #0:1[0x1abf]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:2[0x1ac1]: Unknown: none ([151][0][0][0] / 0x0097)
Unsupported codec with id 0 for input stream 2
Stuff I notice:
The mpg container shouldn't hold h264 video. That messed me up, but remuxing to an mp4 container during the trimming step seemed to make it OK.
The start time isn't anywhere close to zero... but I don't think there's anything wrong with that.
The audio and video are in sync as I watch in a player, but the file contains audio starting nearly 1 second before the video. The first audio packet has pkt_pts_time=92282.982578 (matching the start reported by ffprobe, above), while the first video packet has pkt_pts_time=92283.926411
So I trim it, like so...
ffmpeg -hide_banner -ss 00:17:24 -i myfile.mpg -t 00:02:40 -c copy myfile.trimmed.mp4
[h264 # 000002d5d73f4040] Increasing reorder buffer to 2
[mpegts # 000002d5d73edbc0] PES packet size mismatch
[mpegts # 000002d5d73edbc0] Packet corrupt (stream = 1, dts = 8467425232).
[mpegts # 000002d5d73edbc0] Could not find codec parameters for stream 2 (Unknown: none ([151][0][0][0] / 0x0097)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mpegts # 000002d5d73edbc0] PES packet size mismatch
[mpegts # 000002d5d73edbc0] Packet corrupt (stream = 1, dts = 8467425232).
Input #0, mpegts, from 'myfile.mpg':
Duration: 00:30:00.63, start: 92282.982578, bitrate: 6249 kb/s
Program 1
Stream #0:0[0x1aab]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
Stream #0:1[0x1abf]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:2[0x1ac1]: Unknown: none ([151][0][0][0] / 0x0097)
[mp4 # 000002d5d7e90540] track 1: codec frame size is not set
Output #0, mp4, to 'myfile.trimmed.mp4':
Metadata:
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 59.94 fps, 59.94 tbr, 90k tbn, 90k tbc
Stream #0:1: Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 9570 fps=0.0 q=-1.0 Lsize= 122587kB time=00:02:39.99 bitrate=6276.6kbits/s speed= 462x
video:114772kB audio:7545kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.220873%
ffprobe -hide_banner myfile.trimmed.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'myfile.trimmed.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:02:40.96, start: 0.000000, bitrate: 6239 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 5890 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
Metadata:
handler_name : SoundHandler
Side data:
audio service type: main
...and i get the file that plays fine on a Mac, but not on Windows's default player.
The start time as reported by ffprobe is 0 (above), so that must've been cleaned up by either the trimming or the remuxing. When I look at frames, the first audio packet has a pkt_pts_time=0.000000, and the first video packet has a pkt_pts_time=0.452000.
Where do I go next?
I am having problems with HLS stream creation, sometimes my created video just has audio and it's display a black screen
Here is my code in below
/opt/nodejs/ffmpeg -i "https://******-v1-post-content.s3.us-east-
2.amazonaws.com/104/posts/win/video/item-1615842876280.mov" -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls /tmp/item-1615842876280.m3u8
The Output Of command
stderr: ffmpeg version 4.2.3-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://*****-v1-post-content.s3.us-east-2.amazonaws.com/104/posts/win/video/item-1615842876280.mov:
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2021-03-13T08:49:02.000000Z
Duration: 00:00:03.50, start: 0.000000, bitrate: 7984 kb/s
Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 1920x1080, 7881 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 600 tbc (default)
Metadata:
rotate : 90
creation_time : 2021-03-13T08:49:02.000000Z
handler_name : Core Media Video
encoder : HEVC
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 83 kb/s (default)
Metadata:
creation_time : 2021-03-13T08:49:02.000000Z
handler_name : Core Media Audio
[hls # 0x6684ec0] Opening '/tmp/item-16158428762800.ts' for writing
Output #0, hls, to '/tmp/item-1615842876280.m3u8':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
encoder : Lavf58.29.100
Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 1920x1080, q=2-31, 7881 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 600 tbc (default)
Metadata:
rotate : 90
creation_time : 2021-03-13T08:49:02.000000Z
handler_name : Core Media Video
encoder : HEVC
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 83 kb/s (default)
Metadata:
creation_time : 2021-03-13T08:49:02.000000Z
handler_name : Core Media Audio
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Thank you!
Sevada
I'm trying to copy rtsp stream to ts file by linux command line.
The input stream info:
Input #0, rtsp, from 'rtsp://***.***.***.***:554/****/****/****.smil':
Metadata:
title : live
Duration: N/A, start: 21023.919478, bitrate: 18438 kb/s
Program 1
Metadata:
service_name : *****
service_provider: Harmonic
Stream #0:0: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 1920x1080 [SAR 1:1 DAR 16:9], 17990 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1(eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 448 kb/s
Output #0, mpegts, to '123.ts':
Metadata:
title : live
encoder : Lavf56.40.101
Stream #0:0: Video: mpeg2video ([2][0][0][0] / 0x0002), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 17990 kb/s, 25 fps, 25 tbr, 90k tbn, 90k tbc
Stream #0:1(eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, 448 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
But it return wrong message:
[mpegts # 0x177daa0] first pts value must be set
av_interleaved_write_frame(): Invalid data found when processing input
frame= 11 fps=0.0 q=-1.0 Lsize= 876kB time=00:00:00.79 bitrate=9055.7kbits/s
video:974kB audio:24kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!
And then quit.
My command is worked at another rtsp stream:
Input #0, rtsp, from 'rtsp://***.***.***.***:554/****/****/****.smil':
Metadata:
title : live
Duration: N/A, start: 29796.561522, bitrate: N/A
Program 1
Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
Stream #0:1(eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 192 kb/s
My Download command is:
ffmpeg -rtsp_transport tcp -i "rtsp://***.***.***.***:554/****/****/****.smil" -c copy "`TZ=UTC+8 date "+%Y-%m-%d.%H-%M-%S"`.ts"
I have slove it by myself:
Just modify .ts to .avi
just like
ffmpeg -rtsp_transport tcp -i "rtsp://***.***.***.***:554/****/****/****.smil" -c copy "`TZ=UTC+8 date "+%Y-%m-%d.%H-%M-%S"`.avi"
I've got bunch of movies from two different Panasonic devices. As long as I concat movies from only ONE device - final movie is smooth.
However, when I add movie clip from second device, right after final movie ends playing movies from first device it display audio and only still images from movie clip from other device.
ffmpeg -f concat -i mylist.txt -c copy final_movie.MP4
Example ffprobe:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'S6810001.MP4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.27.100
Duration: 00:00:10.62, start: 0.021333, bitrate: 1131 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 998 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 132 kb/s (default)
Metadata:
handler_name : SoundHandle
Second device movie clip:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a/T00004.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.27.100
Duration: 00:00:33.18, start: 0.000000, bitrate: 1190 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 929 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, stereo, fltp, 256 kb/s (default)
Metadata:
handler_name : SoundHandler
Side data:
audio service type: main
Why movie is still? How to prepare it so it could be joined correctly?
You're trying to concat videos that likely have different profiles. Also, the audio formats are different, but they should be the same if you want to stream copy.
Use ffprobe to view more detailed info about each input:
ffprobe -loglevel error -show_streams S6810001.MP4
ffprobe -loglevel error -show_streams a/T00004.mp4
In this example assuming the video in S6810001.MP4 has Main profile and a/T00004.mp4 has Baseline profile you can "conform" a/T00004.mp4 to be more like S6810001.MP4, or vice versa (note that audio can have a profile too, so make sure you're looking at the right section in the ffprobe output). This example command will use the same profile and same audio format:
ffmpeg -i a/T00004.mp4 -profile:v main -c:a aac a/T00004_encoded.mp4
Now use a/T00004_encoded.mp4 as your second input instead of a/T00004.mp4:
ffmpeg -f concat -i mylist.txt -c copy final_movie.MP4