It is possible to use buildin mov_text MP4 subtitles for HTML5 video player?
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.66.102
Duration: 01:28:55.00, start: 0.000000, bitrate: 908 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 704x400 [SAR 1:1 DAR 44:25], 772 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:2(rus): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
Metadata:
handler_name : SubtitleHandler
Stream #0:3(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
Metadata:
handler_name : SubtitleHandler
Extract subtitles as WebVTT:
ffmpeg -i input.mp4 -map 0:s:0 subs_rus.vtt -map 0:s:1 subs_eng.vtt
Add the subtitles to your HTML5 <video> element:
<track src="subs_rus.vtt" kind="subtitles" srclang="ru" label="русский">
<track src="subs_eng.vtt" kind="subtitles" srclang="en" label="English">
Related
I'm editing a video clip with ffmpeg. The original does not play in Firefox browser by itself. It does normally in Chromium. I do something like:
ffmpeg -ss 00:05:10 -i INPUT.mp4 -c copy OUTPUT.mp4
the resulting clip plays in Firefox but there's no audio. This happens in Firefox (82.0.3), but not in Chromium (86.0.4240.75). In chromium the sound is ok.
If audio is reencoded with
ffmpeg -ss 00:05:10 -i INPUT.mp4 -c:v copy -ab 360kb OUTPUT.mp4
resulting clip is playing ok in Firefox.
Could anyone explain what is happening here and is it possible to cut the mp4 without reencoding audio resulting in a clip that plays in Firefox too?
Some data:
ffmpeg version 3.4.8-0ubuntu0.2
ffprobe INPUT.mp4:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'INPUT.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: iso4avc1isom
creation_time : 2020-11-13T18:45:37.000000Z
com.apple.proapps.clipID: INPUT
com.blackmagic-design.camera.dateRecorded: 2020:11:13
com.apple.proapps.cameraName: 0
com.blackmagic-design.camera.uuid: BDB766E79E646CBB82E3EB986EA1EA-0
Duration: 02:01:38.00, start: 0.000000, bitrate: 6047 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080, 5909 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
Metadata:
creation_time : 2020-11-13T18:45:37.000000Z
handler_name : ?Apple Alias Data Handler
encoder : H264/AVC
timecode : 19:45:35:04
Stream #0:1(eng): Data: none (tmcd / 0x64636D74) (default)
Metadata:
creation_time : 2020-11-13T18:45:37.000000Z
handler_name : ?Apple Alias Data Handler
timecode : 19:45:35:04
Stream #0:2(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2020-11-13T18:45:37.000000Z
handler_name : ?Apple Alias Data Handler
timecode : 19:45:35:04
ffprobe OUTPUT.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'OUTPUT.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 01:34:48.02, start: -0.016000, bitrate: 6022 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 5889 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 12800 tbn, 25600 tbc (default)
Metadata:
handler_name : VideoHandler
timecode : 19:45:35:04
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
Metadata:
handler_name : TimeCodeHandler
timecode : 19:45:35:04
ffprobe the OUTPUT.mp4 that has audio re-encoded and works in Firefox:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Duration: 01:34:48.04, start: 0.000000, bitrate: 6160 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 5889 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 12800 tbn, 25600 tbc (default)
Metadata:
handler_name : VideoHandler
timecode : 19:45:35:04
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 265 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
Metadata:
handler_name : TimeCodeHandler
timecode : 19:45:35:04
EDIT:
I'm providing links to original files, but a bit of warning, they are 4-5GB big each:
original recording from blackmagic switcher/capture/recorder (this does not play in firefox at all, but does in Chromium)
cut version made with -codec copy (plays in firefox but no audio. plays in chromium ok)
cut version with re-encoded audio (plays ok in both firefox and chromium)
My procedure is as follows:
convert the videos to 1920x1080 at 60 FPS (some videos had only 30 FPS)
save the converted videos in a text file
merging the video by an FFMPEG concat
After the videos are merged, the audio is out of sync with the video.
To convert the videos I use the following command: ffmpeg -i input.mp4 -vf scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1 -r 60 output.mp4
(got it from here: How can I upscale videos with FFmpeg to a fixed resolution?)
My FFMPEG command to concat the videos: ffmpeg -f concat -safe 0 -i videolist.txt -c copy final.mp4
When I concatonate the videos, I sometimes get a lot of these warnings:
[mp4 # 0x55740b62ad40] Non-monotonous DTS in output stream 0:1; previous: 336921, current: 336064; changing to 336922. This may result in incorrect timestamps in the output file.
A question for the FFMPEG professionals, how can I make sure that video and audio are in sync?
UPDATE:
Here are the details of the files being listed in the videolist.txt
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'intro.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:07.04, start: 0.000000, bitrate: 291 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 187 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 91 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '4t6Brqa4E5BnD6vC5inICusEtPtd3nU88NgbmUJ.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:37.66, start: 0.000000, bitrate: 1608 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1532 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'cut.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:00.65, start: 0.000000, bitrate: 7128 kb/s
Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 7576 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 115 kb/s (default)
Metadata:
handler_name : IsoMedia File Produced by Google, 5-11-2011
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '80SEh7RoTyVPNj3zTZSaixxATvUYXMNyzu15evs.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:07.75, start: 0.000000, bitrate: 1191 kb/s
Stream #3:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1106 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #3:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 70 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #4, mov,mp4,m4a,3gp,3g2,mj2, from 'outro.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:15.17, start: 0.000000, bitrate: 3417 kb/s
Stream #4:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 3286 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #4:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
All attributes must be the same, but your audio has varying channel layouts (stereo & mono) and sample rates (48000 & 44100).
Add -ar 48000 -ac 2 to your command:
ffmpeg -i input.mp4 -vf scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1 -r 60 -ar 48000 -ac 2 output.mp4
Alternatively, if you want to avoid any temporary files you can do everything in one command using the concat filter as shown in How to concatenate videos in ffmpeg with different attributes?.
I recorded the audio and video stream from a streaming with ffmpeg. when I go to re-encode the file using libx264, the video in the movements looks bad and grainy as in the image.
Where did I go wrong?
this is the code I used
ffmpeg -i input.mp4 -c:v libx264 -c:a aac output.mp4
and these are mediainfo of original file
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isom
creation_time : 2020-03-19T22:43:32.000000Z
Duration: 00:39:51.99, start: 0.000000, bitrate: 1300 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x1080 [SAR 3:2 DAR 16:9], Closed Captions, 1268 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(spa): Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 22 kb/s (default)
Metadata:
handler_name : SoundHandler
mediainfo of the file recoded
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:39:51.99, start: 0.000000, bitrate: 7924 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 7892 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(spa): Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 22 kb/s (default)
Metadata:
handler_name : SoundHandler
How can I recode the file without loss of quality? (sorry for my poor english)
I have recently converted many videos for web playback, but all videos from one "series" all show up in firefox as "Video can't be played because the file is corrupt." (They work for google chrome and VLC. Not for firefox or edge.) All files have been converted with this command:
ffmpeg -i "file.mkv" -vcodec h264 -movflags +faststart -map 0 -vf subtitles="file.mkv" "file.mp4"
ffmpeg output from one of the non-working files:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Episode_7.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.3.100
Duration: 00:23:53.52, start: -0.001333, bitrate: 1900 kb/s
Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1920x1080 [SAR 1:1 DAR 16:9], 1763 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 130 kb/s (default)
Metadata:
handler_name : SoundHandler
ffmpeg output from a working file:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Episode_7.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.3.100
Duration: 00:23:40.06, start: 0.000000, bitrate: 1848 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1710 kb/s, 23.81 fps, 23.81 tbr, 16k tbn, 47.62 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(jpn): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 131 kb/s (default)
Metadata:
handler_name : SoundHandler
Of a collection of over 100 files, only 12 episodes of a single series show up as corrupted in firefox. I see some differences in the information about the two files, but I don't know why one file works and the other does not. What do I need to tell ffmpeg to make the videos playable in firefox?
It's the 4:4:4 chroma sampling. Add -pix_fmt yuv420p to the output file.
I want to change the video metadata.
Orginal video info(ffmpeg -i video.mp4)
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isomavc1mp42
creation_time : 2007-11-22 09:11:58
Duration: 00:00:52.70, start: 0.000000, bitrate: 235 kb/s
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 107 kb/s
Metadata:
creation_time : 2007-11-22 09:11:58
handler_name : (C) 2007 Google Inc. v06.24.2007.
Stream #0:1(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 140x96 [SAR 1:1 DAR 35:24], 125 kb/s, 10 fps, 10 tbr, 10k tbn, 20k tbc
Metadata:
creation_time : 2007-11-22 09:11:58
handler_name : (C) 2007 Google Inc. v06.24.2007.
My ffmpeg shell code:
ffmpeg -i test.mp4 -metadata handler_name="Ahmetka" -i logo.png -filter_complex "overlay=(main_w-overlay_w):(main_h-overlay_h)" output.flv
Output video info(ffmpeg -i output.flv)
Input #0, flv, from 'output.flv':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isomavc1mp42
creation_time : 2007-11-22 09:11:58
encoder : Lavf54.11.100
Duration: 00:00:53.60, start: 0.000000, bitrate: 212 kb/s
Stream #0:0: Video: flv1, yuv420p, 140x96, 200 kb/s, 10 tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s
How can I do?