Как создать миниатюру изображения из видео .flv с помощью ffmpeg?

3214
Shishir Mudliyar

Я использую следующую команду для создания эскиза изображения из FLV видео, изображение создано, но с ошибкой (изображение не открывается)

ffmpeg -ss 00:00:10 -i output.mp4 -f image2 -s 150x150 -vframes 1 -c:v libx264 assetPathNew.jpg  ffmpeg version 0.9.2, Copyright (c) 2000-2012 the FFmpeg developers built on Oct 22 2012 11:15:53 with gcc 4.4.4 20100630 (Red Hat 4.4.4-10) configuration: --enable-libx264 --enable-gpl libavutil 51. 32. 0 / 51. 32. 0 libavcodec 53. 42. 4 / 53. 42. 4 libavformat 53. 24. 2 / 53. 24. 2 libavdevice 53. 4. 0 / 53. 4. 0 libavfilter 2. 53. 0 / 2. 53. 0 libswscale 2. 1. 0 / 2. 1. 0 libpostproc 51. 2. 0 / 51. 2. 0 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 1970-01-01 00:00:00 encoder : Lavf52.64.2 Duration: 00:00:16.96, start: 0.000000, bitrate: 873 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240, 825 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc Metadata: creation_time : 1970-01-01 00:00:00 handler_name : VideoHandler Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 22050 Hz, stereo, s16, 40 kb/s Metadata: creation_time : 1970-01-01 00:00:00 handler_name :  [buffer @ 0xa1c7620] w:320 h:240 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param: [scale @ 0xa1befa0] w:320 h:240 fmt:yuv420p -> w:150 h:150 fmt:yuv420p flags:0x4 [libx264 @ 0xa1bc540] using cpu capabilities: none! [libx264 @ 0xa1bc540] profile High, level 1.1 Output #0, image2, to 'assetPathNew.jpg': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 1970-01-01 00:00:00 encoder : Lavf53.24.2 Stream #0:0(und): Video: h264, yuv420p, 150x150, q=-1--1, 90k tbn, 25 tbc Metadata: creation_time : 1970-01-01 00:00:00 handler_name : VideoHandler Stream mapping: Stream #0:0 -> #0:0 (h264 -> libx264) Press [q] to stop, [?] for help frame= 1 fps= 0 q=28.0 Lsize= 0kB time=00:00:00.-4 bitrate= -0.0kbits/s dup=0 drop=41  video:5kB audio:0kB global headers:0kB muxing overhead -100.000000% [libx264 @ 0xa1bc540] frame I:1 Avg QP:32.24 size: 4707 [libx264 @ 0xa1bc540] mb I I16..4: 0.0% 43.0% 57.0% [libx264 @ 0xa1bc540] 8x8 transform intra:43.0% [libx264 @ 0xa1bc540] coded y,uvDC,uvAC intra: 94.8% 97.0% 74.0% [libx264 @ 0xa1bc540] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 10% 9% 12% 8% 7% 3% 10% 5% [libx264 @ 0xa1bc540] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 17% 13% 10% 7% 8% 6% 10% 8% [libx264 @ 0xa1bc540] i8c dc,h,v,p: 49% 19% 19% 13% [libx264 @ 0xa1bc540] kb/s:941.40 
1

1 ответ на вопрос

4
slhck

When you pass -c:v libx264 after -i, you're telling FFmpeg to encode the input video stream to x264 video. However, you're telling it to write the video to an image2 format, within a JPEG file. This, naturally, won't work. You can actually see this in the stream mapping:

Stream mapping: Stream #0:0 -> #0:0 (h264 -> libx264) 

So let's make FFmpeg write a JPEG image. Use a simple command instead:

ffmpeg -ss 00:00:10 -i output.mp4 -s 150x150 -vframes 1 assetPathNew.jpg 

This time, we get the correct stream mapping:

Stream mapping: Stream #0:0 -> #0:0 (h264 -> mjpeg) 

Note that FFmpeg will automatically choose the right container. You therefore don't need the -f image2.

Using 150x150 will probably create a stretched image and will not keep the original aspect ratio of the input. You can use the scale filter to automatically resize while keeping the aspect ratio:

ffmpeg -ss 00:00:10 -i output.mp4 -filter:v scale=150:-1 -vframes 1 assetPathNew.jpg 

This will most likely give you an output of 150x113. If you must have a size of 150x150, then you can add the pad filter to fill in the extra:

ffmpeg -ss 00:00:10 -i output.mp4 -filter:v "scale=150:-1,pad=iw:150:0:(ow-ih)/2" -vframes 1 assetPathNew.jpg 
Я выполняю следующую обновленную команду ffmpeg -ss 00:00:10 -i output.mp4 -filter: v "scale = 150: -1, pad = iw: 150: 0: (ow-ih) / 2" -vframes 1 assetPathNew.jpg и я получаю следующую ошибку Отображение потока: Поток # 0: 0 -> # 0: 0 (h264 -> mjpeg) Нажмите [q], чтобы остановить, [?] для справочного кадра = 1 fps = 0 q = 4.0 Lsize = 0 кБ время = 00: 00: 00,04 битрейт = 0,0 кбит / с dup = 0 отбрасывание = 41 видео: 7 КБ аудио: 0 КБ глобальные заголовки: 0 КБ накладных расходов на мультиплексирование -100,000000% Shishir Mudliyar 11 лет назад 0
Это не ошибка, правда. Ваше отображение потока правильное, и выводится один кадр. slhck 11 лет назад 0
Я получил это изображение. Спасибо еще раз, чтобы решить проблему, связанную с ffmpeg. Shishir Mudliyar 11 лет назад 0

Похожие вопросы