I recently dipped my feet into encoding with FFmpeg. It's been working fine for me apart form 1 issues I have noticed recently. When I try and re-encode an audio track to acc the media info tags are somewhat wrong. Bitrate, streamsize etc seems to be copied form the source as opposed to reading it from the new track.
Essentially I want to copy the source video, audio and subtitles and also create an AAC version of the soundtrack for playback on devices that don't support HD audio.
Below is an example of what I am doing:
ffmpeg -i source.mkv -map_chapters 0 -map 0:v -c:v copy -c:s copy -map 0:a -c:a:0 copy -map 0:a c:a:1 aac destination.mkv
This results in a media info of:
Audio #1
ID : 2
Format : MLP FBA 16-ch
Format/Info : Meridian Lossless Packing FBA with 16-channel presentation
Commercial name : Dolby TrueHD with Dolby Atmos
Codec ID : A_TRUEHD
Duration : 1 h 50 min
Bit rate mode : Variable
Bit rate : 3 545 kb/s
Maximum bit rate : 5 826 kb/s
Channel(s) : 8 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 48.0 kHz
Frame rate : 1 200.000 FPS (40 SPF)
Bit depth : 24 bits
Compression mode : Lossless
Delay relative to video : 21 ms
Stream size : 2.73 GiB (29%)
Title : Dolby TrueHD 7.1 (Atmos)
Language : English
Default : Yes
Forced : No
Number of dynamic objects : 11
Bed channel count : 1 channel
Bed channel configuration : LFE
Audio #2
ID : 3
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : A_AAC-2
Duration : 1 h 50 min
Bit rate : 3 545 kb/s
Channel(s) : 8 channels
Channel layout : C L R Ls Rs Lb Rb LFE
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 2.73 GiB (29%)
Title : AAC 5.1
Writing library : Lavc58.62.100 aac
Language : English
Default : Yes
Forced : No
As you can see the bit rate, stream size, etc is copied from the source track which is incorrect. I've tried the -map_metadata -1 but that removes the metadata without creating a new one and also removed it from all video and audio tracks which I don't want.
Any other ideas what I am doing wrong or is this just a quirk of the software?
Thanks in advance.
Adding -report output trimming the lines "Writing block of size..." as the file is huge:
ffmpeg started on 2019-12-04 at 14:31:25
Report written to "ffmpeg-20191204-143125.log"
Log level: 48
Command line:
"C:\\ffmpeg\\ffmpeg-20191118-d831edc-win64-static\\bin\\ffmpeg" -i input.mkv -report -map_chapters 0 -map 0:v -c:v copy -c:s copy -map 0:a -c:a:0 copy -map 0:a -c:a:1 aac destination.mkv
ffmpeg version git-2019-11-18-d831edc Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20191010
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 36.100 / 56. 36.100
libavcodec 58. 62.100 / 58. 62.100
libavformat 58. 35.100 / 58. 35.100
libavdevice 58. 9.101 / 58. 9.101
libavfilter 7. 66.100 / 7. 66.100
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'input.mkv'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-map_chapters' ... matched as option 'map_chapters' (set chapters mapping) with argument '0'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:v'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-c:s' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:a'.
Reading option '-c:a:0' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:a'.
Reading option '-c:a:1' ... matched as option 'c' (codec name) with argument 'aac'.
Reading option 'destination.mkv' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url input.mkv.
Successfully parsed a group of options.
Opening an input file: input.mkv.
[NULL # 000001b290ddad00] Opening 'input.mkv' for reading
[file # 000001b290ddbe00] Setting default whitelist 'file,crypto'
[matroska,webm # 000001b290ddad00] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
st:1 removing common factor 1000000 from timebase
[matroska,webm # 000001b290ddad00] Before avformat_find_stream_info() pos: 5080 bytes read:32768 seeks:0 nb_streams:2
[hevc # 000001b290ddeb80] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
[hevc # 000001b290ddeb80] Decoding VPS
[hevc # 000001b290ddeb80] Main 10 profile bitstream
[hevc # 000001b290ddeb80] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
[hevc # 000001b290ddeb80] Decoding SPS
[hevc # 000001b290ddeb80] Main 10 profile bitstream
[hevc # 000001b290ddeb80] Decoding VUI
[hevc # 000001b290ddeb80] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
[hevc # 000001b290ddeb80] Decoding PPS
[hevc # 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0
[hevc # 000001b290ddeb80] Decoding SEI
[hevc # 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0
[hevc # 000001b290ddeb80] Decoding SEI
[hevc # 000001b290ddeb80] nal_unit_type: 39(SEI_PREFIX), nuh_layer_id: 0, temporal_id: 0
[hevc # 000001b290ddeb80] Decoding SEI
[hevc # 000001b290ddeb80] Skipped PREFIX SEI 5
[matroska,webm # 000001b290ddad00] All info found
[matroska,webm # 000001b290ddad00] After avformat_find_stream_info() pos: 10219 bytes read:32768 seeks:0 frames:4
Input #0, matroska,webm, from 'input.mkv':
Metadata:
title : input
ENCODER : Lavf58.35.100
Duration: 01:50:06.89, start: 0.000000, bitrate: 11569 kb/s
Chapter #0:0: start 0.000000, end 308.766792
Metadata:
title : Chapter 01
Chapter #0:1: start 308.766792, end 679.720708
Metadata:
title : Chapter 02
Chapter #0:2: start 679.720708, end 904.820583
Metadata:
title : Chapter 03
Chapter #0:3: start 904.820583, end 1282.781500
Metadata:
title : Chapter 04
Chapter #0:4: start 1282.781500, end 1487.736250
Metadata:
title : Chapter 05
Chapter #0:5: start 1487.736250, end 1846.177667
Metadata:
title : Chapter 06
Chapter #0:6: start 1846.177667, end 2116.531083
Metadata:
title : Chapter 07
Chapter #0:7: start 2116.531083, end 2443.858083
Metadata:
title : Chapter 08
Chapter #0:8: start 2443.858083, end 2731.979250
Metadata:
title : Chapter 09
Chapter #0:9: start 2731.979250, end 3178.383542
Metadata:
title : Chapter 10
Chapter #0:10: start 3178.383542, end 3636.507875
Metadata:
title : Chapter 11
Chapter #0:11: start 3636.507875, end 3867.488625
Metadata:
title : Chapter 12
Chapter #0:12: start 3867.488625, end 4208.037167
Metadata:
title : Chapter 13
Chapter #0:13: start 4208.037167, end 4502.372875
Metadata:
title : Chapter 14
Chapter #0:14: start 4502.372875, end 4853.431917
Metadata:
title : Chapter 15
Chapter #0:15: start 4853.431917, end 5267.470542
Metadata:
title : Chapter 16
Chapter #0:16: start 5267.470542, end 5543.329458
Metadata:
title : Chapter 17
Chapter #0:17: start 5543.329458, end 5847.132958
Metadata:
title : Chapter 18
Chapter #0:18: start 5847.132958, end 6150.269125
Metadata:
title : Chapter 19
Chapter #0:19: start 6150.269125, end 6606.891958
Metadata:
title : Chapter 20
Stream #0:0, 3, 1/1000: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x1600 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc
Metadata:
title : input
ENCODER : Lavc58.62.100 libx265
DURATION : 01:50:06.891000000
Stream #0:1(eng), 1, 1/1000: Audio: truehd, 48000 Hz, 7.1, s32 (24 bit) (default)
Metadata:
title : input
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
BPS-eng : 3544728
DURATION-eng : 01:50:06.893000000
NUMBER_OF_FRAMES-eng: 7928271
NUMBER_OF_BYTES-eng: 2927455224
_STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 ('Old Town Road + Pony') 64-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25
DURATION : 01:50:06.893000000
Successfully opened the file.
Parsing a group of options: output url destination.mkv.
Applying option map_chapters (set chapters mapping) with argument 0.
Applying option map (set input stream mapping) with argument 0:v.
Applying option c:v (codec name) with argument copy.
Applying option c:s (codec name) with argument copy.
Applying option map (set input stream mapping) with argument 0:a.
Applying option c:a:0 (codec name) with argument copy.
Applying option map (set input stream mapping) with argument 0:a.
Applying option c:a:1 (codec name) with argument aac.
Successfully parsed a group of options.
Opening an output file: destination.mkv.
[file # 000001b290ea7e40] Setting default whitelist 'file,crypto'
Successfully opened the file.
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #0:1 -> #0:2 (truehd (native) -> aac (native))
Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:2 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
detected 12 logical cores
[graph_0_in_0_1 # 000001b290dda840] Setting 'time_base' to value '1/48000'
[graph_0_in_0_1 # 000001b290dda840] Setting 'sample_rate' to value '48000'
[graph_0_in_0_1 # 000001b290dda840] Setting 'sample_fmt' to value 's32'
[graph_0_in_0_1 # 000001b290dda840] Setting 'channel_layout' to value '0x63f'
[graph_0_in_0_1 # 000001b290dda840] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x63f
[format_out_0_2 # 000001b290e0ea00] Setting 'sample_fmts' to value 'fltp'
[format_out_0_2 # 000001b290e0ea00] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[format_out_0_2 # 000001b290e0ea00] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_2'
[AVFilterGraph # 000001b290e1b3c0] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 # 000001b290e0fe80] [SWR # 000001b291232000] Using fltp internally between filters
[auto_resampler_0 # 000001b290e0fe80] ch:8 chl:7.1 fmt:s32 r:48000Hz -> ch:8 chl:7.1 fmt:fltp r:48000Hz
[matroska # 000001b290dfba40] get_metadata_duration returned: 6606893000
[matroska # 000001b290dfba40] Write early duration from metadata = 6606893
Output #0, matroska, to 'destination.mkv':
Metadata:
title : input
encoder : Lavf58.35.100
Chapter #0:0: start 0.000000, end 308.766792
Metadata:
title : Chapter 01
Chapter #0:1: start 308.766792, end 679.720708
Metadata:
title : Chapter 02
Chapter #0:2: start 679.720708, end 904.820583
Metadata:
title : Chapter 03
Chapter #0:3: start 904.820583, end 1282.781500
Metadata:
title : Chapter 04
Chapter #0:4: start 1282.781500, end 1487.736250
Metadata:
title : Chapter 05
Chapter #0:5: start 1487.736250, end 1846.177667
Metadata:
title : Chapter 06
Chapter #0:6: start 1846.177667, end 2116.531083
Metadata:
title : Chapter 07
Chapter #0:7: start 2116.531083, end 2443.858083
Metadata:
title : Chapter 08
Chapter #0:8: start 2443.858083, end 2731.979250
Metadata:
title : Chapter 09
Chapter #0:9: start 2731.979250, end 3178.383542
Metadata:
title : Chapter 10
Chapter #0:10: start 3178.383542, end 3636.507875
Metadata:
title : Chapter 11
Chapter #0:11: start 3636.507875, end 3867.488625
Metadata:
title : Chapter 12
Chapter #0:12: start 3867.488625, end 4208.037167
Metadata:
title : Chapter 13
Chapter #0:13: start 4208.037167, end 4502.372875
Metadata:
title : Chapter 14
Chapter #0:14: start 4502.372875, end 4853.431917
Metadata:
title : Chapter 15
Chapter #0:15: start 4853.431917, end 5267.470542
Metadata:
title : Chapter 16
Chapter #0:16: start 5267.470542, end 5543.329458
Metadata:
title : Chapter 17
Chapter #0:17: start 5543.329458, end 5847.132958
Metadata:
title : Chapter 18
Chapter #0:18: start 5847.132958, end 6150.269125
Metadata:
title : Chapter 19
Chapter #0:19: start 6150.269125, end 6606.891958
Metadata:
title : Chapter 20
Stream #0:0, 0, 1/1000: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x1600 [SAR 1:1 DAR 12:5], q=2-31, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc
Metadata:
title : input
ENCODER : Lavc58.62.100 libx265
DURATION : 01:50:06.891000000
Stream #0:1(eng), 0, 1/1000: Audio: truehd ([255][255][255][255] / 0xFFFFFFFF), 48000 Hz, 7.1, s32 (24 bit) (default)
Metadata:
title : input
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
BPS-eng : 3544728
DURATION-eng : 01:50:06.893000000
NUMBER_OF_FRAMES-eng: 7928271
NUMBER_OF_BYTES-eng: 2927455224
_STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 ('Old Town Road + Pony') 64-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25
DURATION : 01:50:06.893000000
Stream #0:2(eng), 0, 1/1000: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, 7.1, fltp (24 bit), 469 kb/s (default)
Metadata:
title : input
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
BPS-eng : 3544728
DURATION-eng : 01:50:06.893000000
NUMBER_OF_FRAMES-eng: 7928271
NUMBER_OF_BYTES-eng: 2927455224
_STATISTICS_WRITING_APP-eng: mkvmerge v40.0.0 ('Old Town Road + Pony') 64-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2019-11-30 10:59:25
DURATION : 01:50:06.893000000
encoder : Lavc58.62.100 aac
cur_dts is invalid st:2 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
....................
....................
[matroska # 000001b290dfba40] Writing block of size 168 with pts 6606913, dts 6606913, duration 1 at relative offset 550755 in cluster at offset 9940898622. TrackNumber 2, keyframe 1
[matroska # 000001b290dfba40] end duration = 6606914
[matroska # 000001b290dfba40] stream 0 end duration = 6606912
[matroska # 000001b290dfba40] stream 1 end duration = 6606914
[matroska # 000001b290dfba40] stream 2 end duration = 6606914
frame=158407 fps=357 q=-1.0 Lsize= 9708475kB time=01:50:06.91 bitrate=12037.7kbits/s speed=14.9x
video:6416483kB audio:3234397kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.596787%
Input file #0 (input.mkv):
Input stream #0:0 (video): 158407 packets read (6570478730 bytes);
Input stream #0:1 (audio): 7928271 packets read (2927455224 bytes); 7928271 frames decoded (317130840 samples);
Total: 8086678 packets (9497933954 bytes) demuxed
Output file #0 (destination.mkv):
Output stream #0:0 (video): 158407 packets muxed (6570478730 bytes);
Output stream #0:1 (audio): 7928271 packets muxed (2927455224 bytes);
Output stream #0:2 (audio): 309699 frames encoded (317130840 samples); 309700 packets muxed (384567176 bytes);
Total: 8396378 packets (9882501130 bytes) muxed
7928271 frames successfully decoded, 0 decoding errors
[AVIOContext # 000001b291230100] Statistics: 8 seeks, 39676 writeouts
[aac # 000001b290dff3c0] Qavg: 3839.668
[AVIOContext # 000001b290de4080] Statistics: 9554742230 bytes read, 0 seeks
You'll need to do it in two steps.
ffmpeg -i source.mkv -map 0:a -c:a aac -map_metadata -1 temp.mkv
ffmpeg -i source.mkv -i temp.mkv -map_chapters 0 -map 0:v -map 0:a -map 1:a -c copy destination.mkv
The reason ffmpeg doesn't give metadata 'bitrate' for the 2nd track is you didn't specifically map the metadata from the added aac audio track. And it was copied, if it had been re-encoded. The bitrate would be shown. Here is it is transcoded in one pass. Notice I set the aac bitrate to 320kb/s. Far less then the TrueHD above 3545 kb/s. 320kb/s is will sound good & your file size will be smaller.
ffmpeg -i source.mkv -map_chapters 0 -map 0:v -map 0:a:0 -map 0:a:0 -map 0:s -c:v copy -c:a:0 copy -c:a:1 aac -b:a:1 320k -c:s copy destination.mkv
Related
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
I am trying to stream video live using ffmpeg. videos stream is coming from a camera over the network and there is bunch error that i got in initial part of doing this but here i am stacked with a error that is coming from ffmpeg where it says av_interleaved_write_frame() broken pipe,then at the end i get a message saying conversion failed ,when i want to capture the stream in any format it works like a charm but when it comes to streaming it gives the error.Why this is happening?
the command i am using to get the streaming is here:
ffmpeg - i rtsp://10.63.191.250/aerostat http://10.20.1.142:8080/feed.ffm
or
ffmpeg - i rtsp://10.63.191.250/aerostat -acodec copy -vcodec copy http://10.20.1.142:8080/feed.ffm
//with both the command i am getting the same error
The ffmpeg out put is Here:
[h264 # 0x3965b40] decode_slice_header error
[h264 # 0x3965b40] no frame!
[h264 # 0x3965b40] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 # 0x3965b40] decode_slice_header error
[h264 # 0x3965b40] no frame!
Input #0, rtsp, from 'rtsp://10.63.191.250/aerostat':
Metadata:
title : \Aerostat
Duration: N/A, start: 63184.792467, bitrate: N/A
Program 1
Stream #0:0: Audio: aac (LC), 48000 Hz, stereo, fltp, 77 kb/s
Stream #0:1: Video: h264 (Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 656x368 [SAR 1:1 DAR 41:23], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
[libvpx # 0x397a360] v1.6.0
Output #0, ffm, to 'http://10.20.1.142:8080/feed.ffm':
Metadata:
title : \Aerostat
creation_time : now
encoder : Lavf57.56.100
Stream #0:0: Audio: vorbis (libvorbis), 22050 Hz, mono, fltp, 64 kb/s
Metadata:
encoder : Lavc57.64.101 libvorbis
Stream #0:1: Video: vp8 (libvpx), yuv420p, 720x576 [SAR 164:115 DAR 41:23], q=10-42, 400 kb/s, 29.97 fps, 1000k tbn, 25 tbc
Metadata:
encoder : Lavc57.64.101 libvpx
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 800000 vbv_delay: -1
Stream mapping:
Stream #0:0 -> #0:0 (aac (native) -> vorbis (libvorbis))
Stream #0:1 -> #0:1 (h264 (native) -> vp8 (libvpx))
Press [q] to stop, [?] for help
av_interleaved_write_frame(): Broken pipe
Last message repeated 6 times
Error writing trailer of http://10.20.1.142:8080/feed.ffm: Broken pipeframe= 6 fps=0.0 q=0.0 Lsize= 52kB time=00:00:00.43 bitrate= 972.0kbits/s dup=5 drop=0 speed=0.778x
video:43kB audio:3kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: 13.661202%
Conversion failed!
Here is My FFserver.conf file:
HTTPPort 8080 # Port to bind the server to
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 10000 # Maximum bandwidth per client
# set this high enough to exceed stream bitrate
CustomLog -
<Feed feed.ffm> # This is the input feed where FFmpeg will send
File ./feed.ffm # video stream.
FileMaxSize 1G # Maximum file size for buffering video
ACL allow 10.20.0.0 10.20.255.255 # Allowed IPs
ACL allow 127.0.0.1
ACL allow localhost
</Feed>
<Stream live.webm> # Output stream URL definition
Feed feed.ffm # Feed from which to receive video
Format webm
# Audio settings
AudioCodec vorbis
Audi0oBitRate 64 # Audio bitrate
# Video settings
VideoCodec libvpx
VideoSize 720x576 # Video resolution
VideoFrameRate 25 # Video FPS
AVOptionVideo flags +global_header # Parameters passed to encoder
# (same as ffmpeg command-line parameters)
AVOptionVideo cpu-used 0
AVOptionVideo qmin 10
AVOptionVideo qmax 42
AVOptionVideo quality good
AVOptionAudio flags +global_header
PreRoll 15
StartSendOnKey
VideoBitRate 400 # Video bitrate
</Stream>
<Stream status.html> # Server status URL
Format status
# Only allow local people to get the status
ACL allow 127.0.0.1
ACL allow 10.20.0.0 10.20.255.255
</Stream>
<Redirect index.html> # Just an URL redirect for index
# Redirect index.html to the appropriate site
URL http://www.ffmpeg.org/
</Redirect>
Summary: I'm trying to limit output to 3mb, .outputOptions('-fs 3000000') isn't working for me, the file is coming back with a size of 119260428 or 119mb.
Here is the code to try for yourself, all you need is a test.mp3 large enough that the resulting testoutput.ogg is > 3mb:
var ffmpeg = require("fluent-ffmpeg");
var command = ffmpeg();
var convertToOGG = function(){
var fileName = 'test.mp3'
ffmpeg.ffprobe(fileName, function(err, metadata) {
command
.input(fileName)
.inputFormat("mp3")
.audioChannels(1)
.outputOptions('-fs', 3000000)
.output('testoutput.ogg')
.on("progress", function(progress) {
console.log("Processing: " + progress.timemark);
})
.on("error", function(err, stdout, stderr) {
console.log("Cannot process video: " + err.message);
})
.on("end", function(stdout, stderr) {
ffmpeg.ffprobe('testoutput.ogg', function(err,metadata){
if(metadata.format.size >= 3000000){
console.log("didn't work")
}
})
})
.run();
});
};
convertToOGG();
Per the fluent-ffmpeg documentation you should be able to use a ffmpeg command in an output option: outputOption()
This method allows passing any output-related option to ffmpeg. You can call it with a single argument to pass a single option, optionnaly
with a space-separated parameter:
/* Single option */
ffmpeg('/path/to/file.avi').outputOptions('-someOption');
and in FFMPEG's documentation:
-fs limit_size (output) Set the file size limit, expressed in bytes. No further chunk of bytes is written after the limit is exceeded. The
size of the output file is slightly more than the requested file size.
It's giving me no errors, just seemingly ignoring the file size limit of 99mb and outputting a 119.3mb file.
Edit - Looks like -fs 3000000 is working for mp3 to wav, but still wont do mp3 to ogg. This is the output from running the command in terminal:
✗ ffmpeg -i test.mp3 -fs 3000000 testoutput.ogg
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
[mp3 # 0x7fc6a4000000] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'test.mp3':
Metadata:
lyrics-eng : xxx
title : xxx
artist : xxx
album_artist : xxx
album : xxx
genre : xxx
Duration: 03:27:28.74, start: 0.000000, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, mono, s16p, 128 kb/s
Stream #0:1: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 540x360, 90k tbr, 90k tbn, 90k tbc
Metadata:
title : Array
comment : Cover (front)
[swscaler # 0x7fc6a4808800] deprecated pixel format used, make sure you did set range correctly
[ogg # 0x7fc6a3815800] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
Output #0, ogg, to 'testoutput.ogg':
Metadata:
lyrics-eng : xxx
title : xxx
artist : xxx
album_artist : xxx
album : xxx
genre : xxx
encoder : Lavf57.56.100
Stream #0:0: Video: theora (libtheora), yuv444p, 540x360, q=2-31, 200 kb/s, 90k fps, 90k tbn, 90k tbc
Metadata:
title : Array
DESCRIPTION : Cover (front)
encoder : Lavc57.64.101 libtheora
lyrics-eng : xxx
artist : xxx
ALBUMARTIST : xxx
album : xxx
genre : xxx
Stream #0:1: Audio: vorbis (libvorbis), 44100 Hz, mono, fltp
Metadata:
encoder : Lavc57.64.101 libvorbis
lyrics-eng : xxx
title : xxx
artist : xxx
ALBUMARTIST : xxx
album : xxx
genre : xxx
Stream mapping:
Stream #0:1 -> #0:0 (mjpeg (native) -> theora (libtheora))
Stream #0:0 -> #0:1 (mp3 (native) -> vorbis (libvorbis))
Press [q] to stop, [?] for help
frame= 1 fps=0.0 q=-0.0 Lsize= 116465kB time=03:27:28.71 bitrate= 76.6kbits/s speed=61.2x
video:9kB audio:114907kB subtitle:0kB other streams:0kB global headers:6kB muxing overhead: 1.347787%
The source mp3 contains a cover image. Attempting to transcode the source file to ogg results in an unusually high framerate for the video stream.
There's a problem with the framerate estimation: 90k fps resembles the stream timebase value:
[ogg # 0x7fc6a3815800] Frame rate very high for a muxer not efficiently supporting it.
[...]
Stream #0:0: Video: theora (libtheora), yuv444p, 540x360, q=2-31, 200 kb/s, 90k fps, 90k tbn, 90k tbc
This could be caused by a problem with the source file, a bug in ffmpeg or maybe both.
A quick solution is to ignore the cover image using either -map 0:a or -vn.
On a Synology drive, I'm trying to transcode audio in an .MKV file from DTS to AAC using the native ffmpeg encoder. But without any error message (at least I don't recognize any here), the audio stream is just missing in the output files. I tried it on several different files, all with the same result, leading to the conclusion that either I'm unable to see the error or something's wrong with FFMPEG. I used the standard FFMPEG package provided with OPKG.
This is the output I usually get:
CirkosDaten> ffmpeg -i encodertest.mkv -map 0 -c:v copy -c:s copy -c:a aac
-strict experimental output.mkv
ffmpeg version 2.0.2 Copyright (c) 2000-2013 the FFmpeg developers
built on Jun 3 2015 06:25:48 with gcc 4.6.4 (Marvell GCC release
20150204-c4af733b 64K MAXPAGESIZE ALIGN CVE-2015-0235)
configuration: --prefix=/usr/syno --incdir='${prefix}/include/ffmpeg'
--arch=arm --target-os=linux --cross-prefix=/usr/local/arm-marvell-linux-
gnueabi/bin/arm-marvell-linux-gnueabi- --enable-cross-compile --enable-
optimizations --enable-pic --enable-gpl --enable-shared --disable-static
--enable-version3 --enable-nonfree --enable-libfaac --enable-encoders
--enable-pthreads --disable-bzlib --disable-protocol=rtp --disable-
muxer=image2 --disable-muxer=image2pipe --disable-swscale-alpha --disable-
ffserver --disable-ffplay --disable-devices --disable-bzlib --disable-
altivec --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-
libmp3lame --disable-vaapi --disable-decoder=amrnb --disable-encoder=zmbv
--disable-encoder=dca --disable-encoder=ac3 --disable-encoder=ac3_fixed
--disable-encoder=eac3 --disable-decoder=dca --disable-decoder=eac3
--disable-decoder=truehd --cc=/usr/local/arm-marvell-linux-gnueabi/bin/arm-
marvell-linux-gnueabi-ccache-gcc
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.1 : 5.1
Guessed Channel Layout for Input Stream #0.2 : 5.1
Input #0, matroska,webm, from 'encodertest.mkv':
Metadata:
title : encodingtest
creation_time : 2012-09-23 09:38:19
Duration: 00:01:00.94, start: 0.000000, bitrate: 9624 kb/s
Chapter #0.0: start 0.000000, end 55.347000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 55.347000, end 60.936000
Metadata:
title : 00:04:56.171
Stream #0:0: Video: h264 (High), yuv420p, 1920x816 [SAR 1:1 DAR 40:17], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
title : encodingtest
Stream #0:1(ger): Audio: dts, 48000 Hz, 5.1 (default)
Metadata:
title : DTS
Stream #0:2(eng): Audio: dts, 48000 Hz, 5.1
Metadata:
title : DTS
Stream #0:3(ger): Subtitle: subrip (default)
Metadata:
title : Forced Subs
Output #0, matroska, to 'output.mkv':
Metadata:
title : encodingtest
encoder : Lavf55.12.100
Chapter #0.0: start 0.000000, end 55.347000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 55.347000, end 60.936000
Metadata:
title : 00:04:56.171
Stream #0:0: Video: h264 (H264 / 0x34363248), yuv420p, 1920x816 [SAR 1:1 DAR 40:17], q=2-31, 23.98 fps, 1k tbn, 1k tbc (default)
Metadata:
title : encodingtest
Stream #0:1(ger): Subtitle: subrip (default)
Metadata:
title : Forced Subs
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:3 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 1461 fps=528 q=-1.0 Lsize= 54636kB time=00:01:00.81 bitrate=7360.1kbits/s
video:54624kB audio:0kB subtitle:0 global headers:0kB muxing overhead
0.023249%encodingtest
When I additionally set the bitrate, the output says
Codec AVOption b (set bitrate (in bits/s)) specified for output file #0
(output.mkv) has not been used for any stream. The most likely reason is
either wrong type (e.g. a video option with no video streams) or that it is
a private option of some encoder which was not actually used for any stream.
This indicates that somehow the 5.1, 48kHz DTS stream isn't considered as an input. Why?
EDIT: Is it possible that DTS decoding is turned off somewhere here? I reckoned maybe that's why I get no errors. But I didn't see any obvious option for that in the output.
OK, I think I found the error:
--disable-decoder=dca
So this armv7 FFmpeg build i used and got via OPKG is compiled without DCA decoding.
Probably I'll need to recompile this on my Disk Station with all the codecs :-( - or does anybody know whether it's possible to just upgrade via IPKG/OPKG?
Does anyone else think building FFmpeg yourself is an ordeal? :-)
EDIT: I just tried to used the standard 32bit package from the FFmpeg project, and indeed it works on armv7 too. Problem solved.
I'm having issue with converting mov files from iPhone 4.
Running this command:
I, [2014-09-15T03:48:33.245231 #9676] INFO -- : Running transcoding...
ffmpeg -y -i /Users/lun/client/bookagoo/public/uploads/5405e9b0486f75a36c100000/video/1410727644xqxzdoxf-IMG_0040_1_.MOV -ss 5 -vframes 1 -f image2 /Users/lun/client/bookagoo/public/uploads/5405e9b0486f75a36c100000/video/1410727644xqxzdoxf-IMG_0040_1_-edited.jpg
E, [2014-09-15T03:48:33.321367 #9676] ERROR -- : Failed encoding...
ffmpeg -y -i /Users/lun/client/bookagoo/public/uploads/5405e9b0486f75a36c100000/video /1410727644xqxzdoxf-IMG_0040_1_.MOV -ss 5 -vframes 1 -f image2 /Users/lun/client/bookagoo/public/uploads/5405e9b0486f75a36c100000/video/1410727644xqxzdoxf-IMG_0040_1_-edited.jpg
My ffmpeg gives me errors like this:
FFMPEG::Error: Failed encoding.Errors: no output file created. Full output: ffmpeg version 2.3.1 Copyright (c) 2000-2014 the FFmpeg developers
built on Aug 20 2014 02:23:29 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.3.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libtheora --enable-libvorbis --enable-libvpx
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 48.100 / 55. 48.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.100 / 4. 11.100
libavresample 1. 3. 0 / 1. 3. 0
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/lun/client/bookagoo/public/uploads/5405e9b0486f75a36c100000/video/1410641311nyv99k1j-IMG_0040_1_.MOV':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2014-07-20 09:47:08
model : iPhone 4
model-rus : iPhone 4
encoder : 7.0.4
encoder-rus : 7.0.4
date : 2014-07-20T13:47:08+0400
date-rus : 2014-07-20T13:47:08+0400
make : Apple
make-rus : Apple
Duration: 00:00:01.84, start: 0.000000, bitrate: 827 kb/s
Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 480x360, 742 kb/s, 23.98 fps, 23.98 tbr, 600 tbn, 1200 tbc (default)
Metadata:
rotate : 90
creation_time : 2014-07-20 09:47:08
handler_name : Core Media Data Handler
encoder : H.264
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default)
Metadata:
creation_time : 2014-07-20 09:47:08
handler_name : Core Media Data Handler
[swscaler # 0x7fe1e9800600] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/Users/lun/client/bookagoo/public/uploads/5405e9b0486f75a36c100000/video/1410641311nyv99k1j-IMG_0040_1_-edited.jpg':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
make-rus : Apple
model : iPhone 4
model-rus : iPhone 4
make : Apple
encoder : Lavf55.48.100
date : 2014-07-20T13:47:08+0400
date-rus : 2014-07-20T13:47:08+0400
Stream #0:0(und): Video: mjpeg, yuvj420p, 480x360, q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc (default)
Metadata:
rotate : 90
creation_time : 2014-07-20 09:47:08
handler_name : Core Media Data Handler
encoder : Lavc55.69.100 mjpeg
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
It's only happening for mov files. There are couple of tricky places it looks like it's trying to take screenshot from a video.
Maybe anyone witnessed anything similar and can give me a tip?
The problem
Your command is telling ffmpeg to skip the first 5 seconds, but the console output indicates that the input duration is only 00:00:01.84 (just under 2 seconds).
Using the select filter
If you're trying to get a screen shot from a variety of inputs with varying durations you can look at the select filter instead of using -ss.
Example to create a mosaic of various scenes:
ffmpeg -i video.avi -vf select='gt(scene\,0.4)',scale=160:120,tile -frames:v 1 preview.png
Using ffprobe with -ss
Alternatively, with some scripting you can use ffprobe to get the duration, and then calculate an appropriate value for -ss.