Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used) 解決方法

提示:簡書對代碼支持不太好,大家可以在我的博客看蜕乡,那的排版好一點

當(dāng)我準備使用ffmpeg截取視頻幀時出現(xiàn)了如題錯誤提示。

使用命令如下:

ffmpeg -ss 15.683 -i /storage/emulated/0/test.mp4 -y -f image2 -t 0.001 /storage/emulated/0/0.jpg

為了便于理解梗夸,在說解決方法之前层玲,先解釋一下這個命令的各參數(shù)用處:

-ss 15.683 :將視頻指向 15.683 秒,也就是從 15.683 秒開始

-i /storage/emulated/0/test.mp4 :輸入 test.mp4 文件

-y:強制覆蓋文件(防止因為重名出錯)

-f image2:文件格式

-t 0.001 :持續(xù)時間(在本例中就相當(dāng)于只取原視頻的第 15.683秒-15.684秒)

/storage/emulated/0/0.jpg:輸出文件路徑

輸入該命令會概率性的輸出空文件反症,并提示以下錯誤:

ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers

built with gcc 4.8 (GCC)

? ? ? configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=

? ? ? libavutil? ? ? 55. 17.103 / 55. 17.103

? ? ? libavcodec? ? 57. 24.102 / 57. 24.102

? ? ? libavformat? ? 57. 25.100 / 57. 25.100

? ? ? libavdevice? ? 57.? 0.101 / 57.? 0.101

? ? ? libavfilter? ? 6. 31.100 /? 6. 31.100

? ? ? libswscale? ? ? 4.? 0.100 /? 4.? 0.100

? ? ? libswresample? 2.? 0.101 /? 2.? 0.101

? ? ? libpostproc? ? 54.? 0.100 / 54.? 0.100

? ? Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/SportsCamera/YDTL0254.mp4':

? ? ? Metadata:

? ? ? ? major_brand? ? : avc1

? ? ? ? minor_version? : 0

? ? ? ? compatible_brands: avc1isom

? ? ? ? creation_time? : 2018-11-21 06:19:31

? ? ? Duration: 00:00:17.98, start: 0.000000, bitrate: 60305 kb/s

? ? ? ? Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc, bt709), 3840x2160, 60301 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)

? ? ? ? Metadata:

? ? ? ? ? creation_time? : 2018-11-21 06:19:31

? ? ? ? ? handler_name? ? :? XiaoYi AVC?

? ? ? ? ? encoder? ? ? ? : Ambarella AVC encoder

? ? Output #0, image2, to '/storage/emulated/0/Android/data/com.equationl.videoshotpro/cache/3.jpg':

? ? ? Metadata:

? ? ? ? major_brand? ? : avc1

? ? ? ? minor_version? : 0

? ? ? ? compatible_brands: avc1isom

? ? ? ? encoder? ? ? ? : Lavf57.25.100

? ? ? ? Stream #0:0(eng): Video: mjpeg, yuvj420p(pc), 3840x2160, q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc (default)

? ? ? ? Metadata:

? ? ? ? ? creation_time? : 2018-11-21 06:19:31

? ? ? ? ? handler_name? ? :? XiaoYi AVC?

? ? ? ? ? encoder? ? ? ? : Lavc57.24.102 mjpeg

? ? ? ? Side data:

? ? ? ? ? unknown side data type 10 (24 bytes)

? ? 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 speed=? 0x? ?

? ? 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)

搜索了一圈沒有發(fā)現(xiàn)類似的問題辛块,而且令人費解的是,該問題是概率性出現(xiàn)惰帽,并且出現(xiàn)時間幾乎找不到任何規(guī)律憨降。

雖然網(wǎng)上沒有發(fā)現(xiàn)有類似的問題,但是我卻發(fā)現(xiàn)我的寫法似乎有點奇怪:

一般來說该酗,使用 ffmpeg 會首先使用 -i?參數(shù)輸入文件再使用 -ss?參數(shù)將其指向需要的位置授药,但是這樣寫的話效率比較低(具體原因網(wǎng)上有很多解釋,我就不多說了)呜魄,所以我先使用 -ss?移動指針再 -i?輸入文件悔叽,問題似乎就出在這了,我看見網(wǎng)上幾乎所有人的寫法都是 -ss?參數(shù)?和 -t?參數(shù)連在一起使用的爵嗅,而我不知道為什么娇澎,居然把他們分開了...

所以當(dāng)我將其放在一起后,就正常了:

ffmpeg -ss 15.683 -t 0.001 -i /storage/emulated/0/test.mp4 -y -f image2 /storage/emulated/0/0.jpg

所以說睹晒,解決方案就是按照錯誤提示所說的趟庄,檢查一下你的 -ss -t -frames?參數(shù)如果你有使用這些參數(shù)的話括细。

不過令我費解的是為什么 -ss?和 -t?分開后會概率性的出現(xiàn)輸出空文件而不是直接100%輸出錯誤呢?希望有大佬能不吝指教戚啥。

下面給大家附上幾個ffmpeg常見錯誤和解決方法吧奋单,讓大家能少踩坑。(下文轉(zhuǎn)自:https://trac.ffmpeg.org/wiki/Errors

Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

When encountered this message is usually the last line in the console output. By itself is not very informative, but it is always accompanied by a more specific message that explains the actual issue, so scroll up for the actual error.

Invalid input file index: 2

The?-map?option is used to choose what inputs you want when default stream selection behavior does not fit your needs. This message can occur when the?-map?option is used to reference an input that does not exist. For example, if you have two inputs, but you're tyring to map a non-existing third input with?-map 2?(note that?ffmpeg?starts counting from?0) then this error will appear.

Properly define your?-map?file index values. See the-map option documentationandFFmpeg Wiki: Mapfor more examples.

Stream map '0:a:0' matches no streams

Similar to the above error, but instead of an incorrect file index there is an incorrect stream index. For example, if the first input contains four video streams, but you use?-map 0:v:4, then you are referencing a non-existing video stream (note that?ffmpeg?starts counting from?0).

Properly define your?-map?stream index values. See the-map option documentationandFFmpeg Wiki: Mapfor more examples. Alternatively, add a trailing???to your map option, such as?-map 0:v:4?, to make the map optional.

Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

The?-ss?option allows you to skip to a certain point. This message is often seen when the?-ss?option value is greater than the duration of the input. For example, if?-ss 30?is used for a 15 second input you may see this message.

Make sure your?-ss,?-t,?-to, and/or?-frames?value does not exceed the input duration.

Unknown encoder 'foo'

Your?ffmpeg?build does not support the encoder you are trying to use.

If it is an external encoder, usually named with the "lib-" prefix, then the build must be compiled to support it. See?ffmpeg -encoders?for a list of encoders supported by your particular build.

You may be using an old, unsupoprted build. Development is very active, so it is recommended to use builds from the current git master branch. See theFFmpeg Downloadpage for options.

The issue could be a simple typo so check the spelling of the encoder name.

Use a current?ffmpeg?build. You may need tocompileit to support your desired encoder. Alternatively, you may simplydownloada static build of?ffmpeg–these builds usually support the most common encoders.

Trailing options were found on the commandline

This message is often overlooked by users and is caused by improper option placement. Placement of options matters, and trailing options are often ignored. Placement is as follows:

ffmpeg [global options] [input options] -i input [output options] output

Thedocumentationwill often specify if an option is global, input, and/or output.

Place your options in the correct location. Options before?-i?will be applied to the input, and options before the output name will be applied to the output. Options after the last output may be ignored.

No pixel format specified, yuv444p for H.264 encoding chosen.

Use -pix_fmt yuv420p for compatibility with outdated media players.

Your input and output may vary in supported pixel formats.?ffmpeg?will attempt to choose the "best" supported pixel format for your encoder. For libx264 it may use a pixel format that is not decodable by many non-FFmpeg based media players.

Adding?-pix_fmt yuv420p?or?-vf format=yuv420p?will ensure compatibility with dumb players.

[image2 @ 0x2e43320] Could not open file : images/output.png.tmp

av_interleaved_write_frame(): Input/output error

In this example the output was?images/output.png, but the?images?directory did not exist.

Check that your directory exists and/or that the permissions are correct.

[image2 @ 0x3841320] Could not get frame filename number 2 from pattern 'output.png' (either set updatefirst or use a pattern like %03d within the filename pattern)

av_interleaved_write_frame(): Invalid argument

This usually occurs because the output name is incorrect or some option was omitted.

If outputting a single image you need to include?-frames:v 1.

If outputting a series of images you need to use the proper naming pattern as described in the image muxer documentation. For example,?output_%03d.png?will make a series named?output_001.png,?output_002.png,?output_003.png, etc.

If outputting a single image that is continuously overwritten with new images, add?-update 1.

[mp4 @ 0x563cd3fa4700] Could not find tag for codec foo in stream #0, codec not currently supported in container

As the message says, the particular codec is not supported in your output container format.

Change the codec and/or output container format.

Streamcopy requested for output stream 0:0, which is fed from a complex filtergraph. Filtering and streamcopy cannot be used together

You can'tstream copy(-c copy,?-codec copy, etc) an output from a filter.

Remove this option or change?copy?to your desired encoder.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末猫十,一起剝皮案震驚了整個濱河市览濒,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌拖云,老刑警劉巖贷笛,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異宙项,居然都是意外死亡乏苦,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進店門杉允,熙熙樓的掌柜王于貴愁眉苦臉地迎上來邑贴,“玉大人,你說我怎么就攤上這事叔磷÷<荩” “怎么了?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵改基,是天一觀的道長繁疤。 經(jīng)常有香客問我,道長秕狰,這世上最難降的妖魔是什么稠腊? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮鸣哀,結(jié)果婚禮上架忌,老公的妹妹穿的比我還像新娘。我一直安慰自己我衬,他們只是感情好叹放,可當(dāng)我...
    茶點故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著挠羔,像睡著了一般井仰。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上破加,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天俱恶,我揣著相機與錄音,去河邊找鬼。 笑死合是,一個胖子當(dāng)著我的面吹牛了罪,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播端仰,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼捶惜,長吁一口氣:“原來是場噩夢啊……” “哼田藐!你這毒婦竟也來了荔烧?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤汽久,失蹤者是張志新(化名)和其女友劉穎鹤竭,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體景醇,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡臀稚,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了三痰。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片吧寺。...
    茶點故事閱讀 39,795評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖散劫,靈堂內(nèi)的尸體忽然破棺而出稚机,到底是詐尸還是另有隱情,我是刑警寧澤获搏,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布赖条,位于F島的核電站,受9級特大地震影響常熙,放射性物質(zhì)發(fā)生泄漏纬乍。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一裸卫、第九天 我趴在偏房一處隱蔽的房頂上張望仿贬。 院中可真熱鬧,春花似錦墓贿、人聲如沸茧泪。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽调炬。三九已至,卻和暖如春舱馅,著一層夾襖步出監(jiān)牢的瞬間缰泡,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留棘钞,地道東北人缠借。 一個月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像宜猜,于是被迫代替她去往敵國和親泼返。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,724評論 2 354

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理姨拥,服務(wù)發(fā)現(xiàn)绅喉,斷路器,智...
    卡卡羅2017閱讀 134,654評論 18 139
  • 超高速音視頻編碼器用法: ffmpeg [options] [[infile options] -i infile...
    吉兇以情遷閱讀 4,603評論 0 4
  • 昨天晚上有夢到你 有一扇門 我推開了 你就那樣躺著 看著我 我的腿沒有跨進去 沒有掉進泥濘里 轉(zhuǎn)身就走 我是不是很棒
    Mareyi閱讀 147評論 0 0
  • 近日昭陽一男子“神預(yù)測”革屠,救20余人一事,刷爆云南人朋友圈排宰,同時在網(wǎng)絡(luò)上引起大批點贊和掌聲似芝! 云南省昭通市大關(guān)縣玉...
    思科德SQD閱讀 352評論 0 1
  • 01 如果古龍先生還在,第七種武器會是什么 很遺憾的是板甘,沒有答案党瓮。江湖傳言,是小馬的拳頭虾啦,或是《英雄無淚》里的箱子...
    鄭公子vega閱讀 901評論 2 9