ffmpeg -i instagram.mp4 -vf fps=29.97 thumb%06d.jpg -hide_banner
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'instagram.mp4': Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.19.104 Duration: 00:00:13.61, start: 0.000000, bitrate: 1163 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x640 [SAR 1:1 DAR 1:1], 1099 kb/s, 29.97 fps,
29.97 tbr, 11988 tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 64 kb/s (default)
Metadata:
handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native)) Press [q] to stop, [?] for help [swscaler # 0x55b2b53cf440] deprecated pixel format used, make sure
you did set range correctly Output #0, image2, to 'thumb%06d.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 640x640 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc57.107.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 frame= 405 fps=231 q=24.8 Lsize=N/A time=00:00:13.51 bitrate=N/A speed=7.72x video:5961kB audio:0kB subtitle:0kB other streams:0kB
global headers:0kB muxing overhead: unknown
The video duration is 13.61 seconds and frame rate is 29.97. So I was expecting 13.61 * 29.97 = 407.8917 i.e. 407 frames. But have got 405 frames. I am new to ffmpeg, need help to correctly get all 407 frames.
I had also tried following command,
ffmpeg -i instagram.mp4 thumb%06d.jpg -hide_banner
but the output was same 405 frames.
Possibly the start 2 frames are missing.
I need to display the frames generated in the base video timeline. And on clicking on the frame I need to exactly seek the video to the frame position using HTML5 currentTime. Since the first 2 frames are not getting available, exact mapping is not getting possible.
Please guide.
have you try to use -vsync vfr or -vsync 0 disables the frame drop/dup behaviour?
#Gyan
Please refer to this question.
https://superuser.com/questions/1374584/why-does-ffmpeg-extracts-a-lot-more-frames-than-the-actual
Related
Env: Windows7, ffmpeg 4.2.2
copy the first 10 seconds from long.mp4 to UNO.mp4
copy sec 120 to sec 130 from long.mp4 to DUE.mp4
create List.txt with
file 'C:\Users\Admin\Videos\UNO.mp4'
file 'C:\Users\Admin\Videos\DUE.mp4'
here the ffprobe output of the two files:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'UNO.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:00:10.04, start: 0.000000, bitrate: 671 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x360 [SAR 1:1 DAR 16:9], 536 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 09/18/2020.
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 09/18/2020.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'DUE.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:00:11.96, start: 0.000000, bitrate: 657 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x360 [SAR 1:1 DAR 16:9], 524 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 09/18/2020.
Stream #0:1(und): 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: 09/18/2020.
use the two files as input to
ffmpeg -f concat -safe 0 -i "C:\Users\Admin\Videos\List.txt" -c copy "C:\Users\Admin\Videos\mergedVideo.mp4"
it outputs:
mov,mp4,m4a,3gp,3g2,mj2 # 00be7f80] Auto-inserting h264_mp4toannexb bitstream filter
nput #0, concat, from 'C:\Users\Admin\Videos\List.txt':
Duration: N/A, start: 0.000000, bitrate: 825 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 624x352 [SAR 1:1 DAR 39:22], 697 kb/s, 25 fps, 25
tbr, 90k tbn, 50 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
handler_name : SoundHandler
utput #0, mp4, to 'C:\Users\Admin\Videos\mergedVideo.mp4':
Metadata:
encoder : Lavf58.29.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 624x352 [SAR 1:1 DAR 39:22], q=2-31, 697 kb/s, 25
fps, 25 tbr, 90k tbn, 90k tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
handler_name : SoundHandler
tream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
then a long series of :
mp4 # 00c43c40] Non-monotonous DTS in output stream 0:0; previous: 899370, current: 720000; changing to 899371. This may result in incorrect timestamps in the output file.
at end as last messages :
rame= 552 fps=528 q=-1.0 Lsize= 2220kB time=00:00:20.01 bitrate= 908.4kbits/s speed=19.2x
ideo:1873kB audio:329kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.827539%
When i play the output mergedVideo.mp4 with ffplay, it does not gove errors
it is only a time stamp problem, or some frames or some audio are lost ?
in the latter case, is there a parameter to correct the problem, or i have to re-encode ?
(to further test, i tried with avidemux an it concats UNO.mp4 and DUE.mp4 without re-encoding)
Thanks in advance to all for the support
Maurizio
First of all, unless you call FFmpeg with the -xerror option (which you didn't) "Non-monotonous DTS..." message is not an error. It's just a warning. It is just informing what it's doing for you, and thankfully its automatic adjustment indeed worked for your case base on your description.
It is making the adjustment because you are concatenate-and-copying streams, of which data frame carries timestamp (unlike WAV or MPEG streams). The concat demuxer likely cannot adjust the timestamp in the stream data on the fly (to avoid the warnings/corrections from the main ffmpeg program).
The bottom line. If the warning messages must go, change the log level to ignore warning: -loglevel error.
Reference ffmpeg.c Lines 817-834
ffmpeg -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -c:v
mpeg4_cuvid -i "F:\dataset\celeb-df-v1\Celeb-real\id0_0002.mp4"
-vcodec mpeg4 -b:v 574k -y "F:\dataset\celeb-df-v1\compress\id0_0002.mp4"
It keeps reporting errors like:
Impossible to convert between the formats supported by the filter
'Parsed_null_0' and the filter 'auto_scaler_0' Error reinitializing
filters! Failed to inject frame into filter network: Function not
implemented Error while processing the decoded data for stream #0:0
Here is my video info
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'F:\dataset\celeb-df-v1\\Celeb-real\id0_0002.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.3.100
Duration: 00:00:11.67, start: 0.000000, bitrate: 1148 kb/s
Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 942x500 [SAR 1:1 DAR 471:250], 1146 kb/s, 30 fps, 30 tbr, 90k tbn, 30 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 (mpeg4_cuvid) -> mpeg4 (native))
Press [q] to stop, [?] for help
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.
Is it possible to manually embed timed text metadata into MP4 files?
I have a TTML / SRT file with the metadata. I just need to embed the text data without doing any encoding the video / audio.
EDIT:
We used to do the metadata injecting using on Wowza server which we use for live streaming. What I need to do is manually inject the metadata in to prerecorded MP4 files without running the video through Wowza.
Here is one such video file that was processed by Wowza:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'metadata-back.mp4':
Metadata:
major_brand : f4v
minor_version : 0
compatible_brands: isommp42m4v
creation_time : 2015-04-16 11:12:39
Duration: 00:00:11.70, start: 0.000000, bitrate: 1373 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv), 640x480 [SAR 1:1 DAR 4:3], 1352 kb/s, 28.60 fps, 30 tbr, 90k tbn, 60 tbc (default)
Metadata:
creation_time : 2015-04-16 11:12:39
handler_name : WowzaStreamingEngine
encoder : WowzaStreamingEngine
Stream #0:1(eng): Audio: speex (spex / 0x78657073), 16000 Hz, mono, s16, 17 kb/s (default)
Metadata:
creation_time : 2015-04-16 11:12:39
handler_name : WowzaStreamingEngine
Stream #0:2(eng): Data: none (amf0 / 0x30666D61), 0 kb/s (default)
Metadata:
creation_time : 2015-04-16 11:12:39
handler_name : WowzaStreamingEngine
Now if I run the command ffmpeg -i new-meta.mp4 -i sub.srt -c copy -c:s mov_text -movflags +faststart out.mp4 and if I run ffmpeg -i out.mp4, I get this:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.4.101
Duration: 00:00:07.27, start: 0.000000, bitrate: 925 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1366x768 [SAR 1:1 DAR 683:384], 920 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
Metadata:
handler_name : SubtitleHandler
Now as you can see the text is embedded with a different codec (is this the right term?). Also I dont see an audio track as well.
Hope my question is clear enough. I need a way to embed metadata (from srt / ttml) into an MP4 video it should be embedded in amf format (again is this the right term?)
ffmpeg -i in.mp4 -i subs.srt -c copy -c:s mov_text -movflags +faststart out.mp4
Support for 3GPP TS 26.245 Timed Text ("mov_text") in MP4 may vary according to the player.
I use
call(['avconv', '-i', 'video.mp4', '-vsync', '1','-r', '1','-an','-y','%5d.jpg'])
in Python. It works, but it goes through the videofile in realtime. How to speed this up, so getting 60 pictures all in all, each second of the video file does not take 1 minute but less.
The following Python code extracts 60 seconds worth of frames as fast as possible, and outputs them as JPEG files in the current directory.
source
from subprocess import call
call([
'avconv', '-i', 'video.mp4',
'-vsync', '1',
'-r', '1',
'-an', '-y',
'-t', '60', # 60 seconds = 60 pictures
'%5d.jpg',
])
output
avconv version 0.8.9-6:0.8.9-0ubuntu0.13.10.1, Copyright (c) 2000-2013 the Libav developers
built on Nov 9 2013 19:09:46 with gcc 4.8.1
[mov,mp4,m4a,3gp,3g2,mj2 # 0x14bbe00] multiple edit list entries, a/v desync might occur, patch welcome
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf53.21.1
Duration: 01:59:16.23, start: 0.000000, bitrate: 1153 kb/s
Stream #0.0(und): Video: mpeg4 (Advanced Simple Profile), yuv420p, 480x368 [PAR 1:1 DAR 30:23], 1016 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 23.98 tbc
Stream #0.1(und): Audio: aac, 48000 Hz, mono, s16, 63 kb/s
Stream #0.2(und): Audio: aac, 48000 Hz, mono, s16, 64 kb/s
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[buffer # 0x1670a20] w:480 h:368 pixfmt:yuv420p
[avsink # 0x147f6a0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale # 0x14bf520] w:480 h:368 fmt:yuv420p -> w:480 h:368 fmt:yuvj420p flags:0x4
Output #0, image2, to '%5d.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf53.21.1
Stream #0.0(und): Video: mjpeg, yuvj420p, 480x368 [PAR 1:1 DAR 30:23], q=2-31, 200 kb/s, 90k tbn, 1 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 -> mjpeg)
Press ctrl-c to stop encoding
frame= 62 fps= 37 q=11.2 Lsize= -0kB time=62.00 bitrate= -0.0kbits/s dup=0 drop=1375
video:1784kB audio:0kB global headers:0kB muxing overhead -100.001204%