Extract frames from video with ffmpeg - header problem? - image

I want to convert .AVI files coming from a camera-trap to individuals frames, ideally using ffmpeg. Up to now I am not succeeding.
The most simple thing I tried, to try to locate the problem, is this (I want all frames and my test file is test.avi):
ffmpeg -i test.avi output_%04d.png
It fails with the following console message:
[avi # 0x559fb596f8c0] unknown stream type 73647578
[avi # 0x559fb596f8c0] Something went wrong during header parsing, tag [0][0]id has size 338702712, I will ignore it and try to continue anyway.
[mjpeg # 0x559fb59709e0] No JPEG data found in image
Last message repeated 100 times
[avi # 0x559fb596f8c0] decoding for stream 0 failed
[avi # 0x559fb596f8c0] Could not find codec parameters for stream 0 (Video: mjpeg (MJPG / 0x47504A4D), none(bt470bg/unknown/unknown), 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[avi # 0x559fb596f8c0] Could not find codec parameters for stream 1 (Video: none (JUNK / 0x4B4E554A), none, 11025x22050): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, avi, from 'test.avi':
Duration: 00:00:10.50, start: 0.000000, bitrate: 28129 kb/s
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), none(bt470bg/unknown/unknown), 1280x720, 20.01 fps, 20.01 tbr, 20.01 tbn, 20.01 tbc
Stream #0:1: Video: none (JUNK / 0x4B4E554A), none, 11025x22050, 11025 tbr, 11025 tbn, 11025 tbc
Stream mapping:
Stream #0:1 -> #0:0 (? (?) -> png (native))
Decoder (codec none) not found for input stream #0:1
The actual video duration is 10s (when read using vlc for instance, and this is indeed the length of video programmed on the camera-trap. ffmpeg says the duration is 10.50s, and says there is a problem with header parsing (see above).
I have no idea how to sort this, despite having looked at more than many ffmpeg 'convert video to frames' post. Any hint would be appreciated, thanks.

If you look at the error message, you will see that the file has 2 video streams.
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), none(bt470bg/unknown/unknown), 1280x720, 20.01 fps, 20.01 tbr, 20.01 tbn, 20.01 tbc
Stream #0:1: Video: none (JUNK / 0x4B4E554A), none, 11025x22050, 11025 tbr, 11025 tbn, 11025 tbc
and ffmpeg is trying to read for the second one:
Stream mapping:
Stream #0:1 -> #0:0 (? (?) -> png (native))
You can use -map 0:0 to select the first stream.

Related

Split a live video stream from a webcam with ffmpeg [duplicate]

I need to split a large video file into multiple pieces quickly and without files with errors. The basic idea is, I have a 2GB video file which I want to change to multiple formats. I have read some encoders can not make use of more than 1 core when encoding to a different format. So I had the idea to split the large file (which is very quick) into 4/8 pieces depending on how many cores I have available on individual servers. re-encode each piece to a new format and use these to display video in sequence.
so
testfile.mp4
becomes
testfile_piece_1.mp4
testfile_piece_2.mp4
testfile_piece_3.mp4
testfile_piece_4.mp4
these can then be individually be converted.
The solution should not be format specific. However I have found issues with mp4 files.
I have tried the command below, which works really well and fast but creates files with errors.
ffmpeg -i testfile.mp4 -ss 00:00:00 -t 00:20:00 -c copy testfile_piece_1.mp4
When I play the testfile_piece_1.mp4 on VLC it works fine. An issue arises when converting the split file to a different height and width mp4 file. I would get an error similar to "moov atom not found"
I tried adding -movflags faststart with no luck
I then came across this library https://code.google.com/archive/p/moovrelocator/ which fixed the moov issue but I would then get an error with regards to aac "Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height"
The other way of splitting the files is useless but involved re-encoding the file. not too bad for smaller file size but the 2GB file would probably take days to complete.
Is there a way to split the largr file quickly without producing files with errors? I have been working on it for days with no luck.
Console output for comment - FFmpeg splitting large files
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/share/nginx/html/uploads/testfile01.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.36.100
Duration: 00:05:02.08, start: 302.120000, bitrate: 3254 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709) , 1920x1080 [SAR 1:1 DAR 16:9], 3252 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (de fault)
Metadata:
handler_name : VideoHandler
[libx264 # 0x165ffc0] width not divisible by 2 (853x480)
Output #0, mp4, to '/usr/share/nginx/html/uploads/testfile01_480.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.36.100
Stream #0:0(und): Video: h264, none, q=2-31, 128 kb/s, SAR 2560:2559 DAR 0:0 , 25 fps (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc56.41.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
console output 2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/share/nginx/html/uploads/testfile.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
creation_time : 2016-01-24 04:26:37
Duration: 01:15:58.08, start: 0.000000, bitrate: 3163 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 3161 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
creation_time : 2016-01-24 04:26:37
handler_name : VideoHandler
[segment # 0x1197060] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, segment, to '/usr/share/nginx/html/uploads/testfile%02d.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
encoder : Lavf56.36.100
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 3161 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
Metadata:
creation_time : 2016-01-24 04:26:37
handler_name : VideoHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
[mp4 # 0x11512a0] Codec for stream 0 does not use global headers but container format requires global headers
Use the segment muxer to break the input into segments:
ffmpeg -i testfile.mp4 -c copy -f segment -segment_time 1200 testfile_piece_%02d.mp4
This will split the source at keyframes, so segments may not be exactly 1200 seconds long. And the timestamps aren't reset, so some players will fail to play the 2nd and latter segments. If playability is needed, insert -reset_timestamps 1.
After the parallel encoding, you can stitch the generated segments by first creating a text file seg.txt like this
file 'encoded_testfile_piece_00.mp4'
file 'encoded_testfile_piece_01.mp4'
file 'encoded_testfile_piece_02.mp4'
file 'encoded_testfile_piece_03.mp4'
And then running
ffmpeg -f concat -i seg.txt -c copy -fflags +genpts encoded_full.mp4

ffmpeg codec conversion; can't configure encoder

I am simply trying to convert a vp9 webm I have into a vp8 webm. this is the command I'm using.
ffmpeg -i in.webm -c:v vp8 out.webm
the vp8 encoder returns a strange error
Input #0, matroska,webm, from 'in.webm':
Metadata:
encoder : google
Duration: 00:02:34.60, start: 0.000000, bitrate: 404 kb/s
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown), 640x360, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Stream mapping:
Stream #0:0 -> #0:0 (vp9 (native) -> vp8 (vp8_v4l2m2m))
Press [q] to stop, [?] for help
[vp8_v4l2m2m # 0x56195db9f9f0] Could not find a valid device
[vp8_v4l2m2m # 0x56195db9f9f0] can't configure encoder
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
In case I get any questions about whether I have the right encoders and decoders installed here is the output of ffmpeg -codecs | grep "vp[8-9]":
DEV.L. vp8 On2 VP8 (decoders: vp8 vp8_v4l2m2m vp8_cuvid ) (encoders: vp8_v4l2m2m )
D.V.L. vp9 Google VP9 (decoders: vp9 vp9_v4l2m2m vp9_cuvid )
Your ffmpeg build has a Video4Linux wrapper available for a hardware VP8 encoder, but no actual hardware VP8 encoder available.
For software encoding of VP8/VP9, you'll need libvpx enabled and linked. You can get a static git binary from https://johnvansickle.com/ffmpeg/

Ffmpeg didn't burn srt subtitle on mkv properly

`ffmpeg version:git-fc6de70 (2013-07-18) with libass and fontconfig support.
command line:ffmpeg.exe -i test.mkv -vf subtitles=test.srt out.mkv
and i got this error.:
Metadata:
encoder : Lavf55.12.102
Stream #0:0(eng): Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1280x5
76 [SAR 1:1 DAR 20:9], q=-1--1, 1k tbn, 23.98 tbc (default)
Stream #0:1: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 48000 Hz, stereo
, fltp (default)
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> libvorbis)
Press [q] to stop, [?] for help
[Parsed_subtitles_0 # 00000000027b9960] Neither PlayResX nor PlayResY defined. A
ssuming 384x288
http://tinypic.com/r/2ag52so/5
The message you get:
[Parsed_subtitles_0 # 00000000027b9960] Neither PlayResX nor PlayResY defined. Assuming 384x288
means that your ssa or srt file doesn't specify the PlayResX and Y values. So the VFilter assume a display resolution of 384x288, thats why your subtitles looks so small on a 1280x576 video.
A workaround for your issue is:
convert SRT to SSA/ASS
ffmpeg -i file.srt file.ass
edit your SSA/ASS file to set the correct value. For SSA the format is describe here and it's easy to set PlayRes X and Y.
[Script Info]
; This is a Sub Station Alpha v4 script.
....
ScriptType: v4.00
Collisions: Normal
PlayResX: 1280
PlayResY: 576
PlayDepth: 0
....
And finally, launch your command again using the ass file.
Burning subntitles with FFmpeg is tricky due to canvas size with pictured-based subtitles and charset encoding with text files (srt or ssa).
I guess I managed to handle it for almost all cases in DVDx 4.1 Free Encoder version (Beta 1.0):
http://www.labdv.com/dvdx/4.1/docs/burn-subtitles-in-video.php

Increase the bitrate tolerance of ffmpeg for creating screenshots of a movie

I'm getting the error bitrate tolerance too small for bitrate so far no problem. I know that there are several switches to increase that but nothing works.
ffmpeg -y -r 1/30 -b:v 999999k -bt 999999k -maxrate 999999k -i in.flv out%03d.jpg
The source of that commandline is directly from ffmpeg. But that crashes:
ffmpeg version N-44123-g5d55830 Copyright (c) 2000-2012 the FFmpeg developers
built on Sep 2 2012 20:23:29 with gcc 4.7.1 (GCC)
[...]
Input #0, flv, from 'in.flv':
Duration: 00:05:00.13, start: 0.000000, bitrate: 259 kb/s
Stream #0:0: Video: flv1, yuv420p, 320x240, 1k tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: nellymoser, 22050 Hz, mono, s16
[mjpeg # 04356860] bitrate tolerance too small for bitrate
[mjpeg # 04317540] ff_frame_thread_encoder_init failed
Output #0, image2, to 'out%03d.jpg':
Stream #0:0: Video: mjpeg, yuvj420p, 320x240, q=2-31, 200 kb/s, 90k tbn, 0.03 tbc
Stream mapping:
Stream #0:0 -> #0:0 (flv -> mjpeg)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Some ideas what I'm doing wrong?

How to use ffmpeg to add a text to avi video?

I am trying to put a simple text on the bottom of video using ffmpeg on Ubuntu 12.04 . I tried this which is suggested in several places:
ffmpeg -i input.avi -vf drawtext="fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf:text='Text to write':fontsize=20:fontcolor=black:x=100:y=100" output.avi
But I get this error each time:
ffmpeg version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
built on Jun 12 2012 16:37:58 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, avi, from 'input.avi':
Duration: 04:09:09.66, start: 0.000000, bitrate: 480 kb/s
Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 320x240 [PAR 1:1 DAR 4:3], 45 tbr, 45 tbn, 45 tbc
Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 64 kb/s
[buffer # 0x860d5a0] w:320 h:240 pixfmt:yuv420p
Incompatible sample format 's16' for codec 'ac3', auto-selecting format 'flt'
[ac3 # 0x8607a00] invalid bit rate
Output #0, avi, to 'output.avi':
Stream #0.0: Video: mpeg4, yuv420p, 320x240 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 45 tbc
Stream #0.1: Audio: ac3, 48000 Hz, stereo, flt, 200 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Error while opening encoder for output stream #0.1 - maybe incorrect parameters such as bit_rate, rate, width or height
Appreciate your help.
The documentation shows that you can use other parameters with x or y such as input video height and width and text width and height. To place the text on the bottom one method is y=main_h-text_h. If you want a little padding on the bottom you can use y=main_h-(text_h*2) To center it horizontally use x=(main_w/2-text_w/2).

Resources