ffmpeg can't concat movies from two different devices - linux

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

Related

ffmpeg - 2nd audio stream added to video won't play

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.

Trimmed a video with ffmpeg; looks fine on a Mac, but audio/video are 3 seconds out of sync with Windows default player. Huh?

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?

After video convert to hls with ffmpeg, new video has no screen and has just audio

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

Why ffmpeg -rtsp_transport tcp -i can not copy the rtsp stream with service_provider: Harmonic?

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"

How to concat multiple video files which have different stream order with FFmpeg?

I have 3 video files with following info:
Input #0, mpegts, from '01.ts':
Duration: 00:00:06.08, start: 0.000000, bitrate: 931 kb/s
Program 1
Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 65 kb/s
Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #0, mpegts, from '02.ts':
Duration: 00:00:06.06, start: 6.016000, bitrate: 872 kb/s
Stream #0:0[0x102]: Video: h264 (High), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac (LC), 48000 Hz, stereo, fltp, 66 kb/s
Input #0, mpegts, from '03.ts':
Duration: 00:00:06.07, start: 12.010667, bitrate: 822 kb/s
Stream #0:0[0x102]: Video: h264 (High), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac (LC), 48000 Hz, stereo, fltp, 69 kb/s
Most of them are the same, but somehow 01.ts has different stream order with the other two. My question is, how to concat them? I've tried to put them in a txt file and concat:
-f concat -safe 0 -i video_file.txt -c copy -bsf:a aac_adtstoasc output.mp4
But it's not working. Error message is:
Error parsing ADTS frame header!
Error applying bitstream filters to an output packet for stream #0:1.
And what if I have hundreds of video files that may have diffrent stream order like this?
EDIT
aergistal's answer is correct, but I have another problem: in another collection of videos, the stream ids are different, as following:
Input #0, mpegts, from 'another1.ts':
Duration: 00:00:08.04, start: 17.401333, bitrate: 284 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 352x288 [SAR 16:11 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 124 kb/s
Input #0, mpegts, from 'another2.ts':
Duration: 00:00:08.04, start: 33.401333, bitrate: 300 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 352x288 [SAR 16:11 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 145 kb/s
Is there a way to set the exact_stream_id automatically instead of check it everytime?
The concat demuxer has an exact_stream_id which might help. Use the PIDs and the following format for your concat list (video_file.txt):
file 01.ts
stream
exact_stream_id 0x102
stream
exact_stream_id 0x101
file 02.ts
stream
exact_stream_id 0x102
stream
exact_stream_id 0x101
file 03.ts
stream
exact_stream_id 0x102
stream
exact_stream_id 0x101

Resources