2015-12-24 49 views
1

視頻幀差我需要計算一個源的視頻和壓縮的一個之間的幀間差。 現在我正在使用OpenCVJava,通過提取每幀並做一個簡單的區別,但它很慢(工作0.5 fps,這意味着500幀視頻將花費超過15分鐘),所以我想移動到FFMPEG與FFMPEG

FFMPEG感覺快很多(一切都在1分鐘執行),但它有一個很大的問題,使得結果無用:壓縮的源文件,以FFMPEG太完成後,一個額外的灰色框是在加入開始並且由於不同的幀被比較而僞造結果。重新編碼

ffmpeg -y -i src.avi -i compressed.avi -filter_complex "blend=all_mode=difference,hue=s=0" -c:v libx264 -crf 18 -c:a copy difference.avi 

要解決這個問題幀我試圖通過去除第一幀的壓縮視頻:

這是我現在在做什麼(知道額外的框架打亂了一切)使用此命令

ffmpeg -y -ss 0.02 -i compressed.mpg -an -f mpeg2video compressed-cut.mpg" 

(注意-ss0.02因爲它是一個50 fps的視頻,所以我做了1/FPS的建議here

但我得到這個響應

輸出文件是空的,什麼也沒有編碼,如果使用(檢查-ss/-t/-frames參數)

所以,最後,問題是:因爲提取所有的幀,然後用OpenCV的計算的差異實在是太慢了,我該如何使用FFMPEG生產含有兩個源之間的差異的視頻,同時牢記其中一人有支付額外框架該會軋花?

編輯:我想避免無休止的發佈控制檯輸出,但既然你自找的,在這裏我們去。

1)編碼

輸入

ffmpeg -i "720p50_mobcal_ter.avi" -an -f mpeg2video -y "720p50_mobcal_ter.mpg" 

輸出

ffmpeg version N-76684-g1fe82ab Copyright (c) 2000-2015 the FFmpeg developers 
    built with gcc 5.2.0 (GCC) 
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib 
    libavutil  55. 6.100/55. 6.100 
    libavcodec  57. 15.100/57. 15.100 
    libavformat 57. 14.100/57. 14.100 
    libavdevice 57. 0.100/57. 0.100 
    libavfilter  6. 15.100/6. 15.100 
    libswscale  4. 0.100/4. 0.100 
    libswresample 2. 0.101/2. 0.101 
    libpostproc 54. 0.100/54. 0.100 
Input #0, avi, from '720p50_mobcal_ter.avi': 
    Metadata: 
    encoder   : Lavf57.14.100 
    Duration: 00:00:10.08, start: 0.000000, bitrate: 552974 kb/s 
    Stream #0:0: Video: rawvideo (I420/0x30323449), yuv420p, 1280x720, 554059 kb/s, SAR 1:1 DAR 16:9, 50 fps, 50 tbr, 50 tbn, 50 tbc 
Output #0, mpeg2video, to '720p50_mobcal_ter.mpg': 
    Metadata: 
    encoder   : Lavf57.14.100 
    Stream #0:0: Video: mpeg2video, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 50 fps, 50 tbn, 50 tbc 
    Metadata: 
     encoder   : Lavc57.15.100 mpeg2video 
Stream mapping: 
    Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg2video (native)) 
Press [q] to stop, [?] for help 
frame= 41 fps=0.0 q=31.0 size=  984kB time=00:00:00.78 bitrate=10330.5kbits/frame= 80 fps= 78 q=31.0 size= 1323kB time=00:00:01.56 bitrate=6948.1kbits/frame= 124 fps= 80 q=31.0 size= 1725kB time=00:00:02.44 bitrate=5790.0kbits/frame= 168 fps= 81 q=31.0 size= 2084kB time=00:00:03.32 bitrate=5142.8kbits/frame= 212 fps= 81 q=31.0 size= 2482kB time=00:00:04.20 bitrate=4841.4kbits/frame= 255 fps= 82 q=31.0 size= 2840kB time=00:00:05.06 bitrate=4597.2kbits/frame= 296 fps= 82 q=31.0 size= 3133kB time=00:00:05.88 bitrate=4364.5kbits/frame= 338 fps= 82 q=24.8 size= 3453kB time=00:00:06.72 bitrate=4209.2kbits/frame= 382 fps= 82 q=31.0 size= 3723kB time=00:00:07.60 bitrate=4013.4kbits/frame= 426 fps= 83 q=31.0 size= 4005kB time=00:00:08.48 bitrate=3869.1kbits/frame= 470 fps= 83 q=24.8 size= 4276kB time=00:00:09.36 bitrate=3742.5kbits/frame= 504 fps= 83 q=31.0 Lsize= 4469kB time=00:00:10.06 bitrate=3639.3kbits/s 
video:4469kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000% 

這增加了在開始時額外灰色框,它只是複製的第一個

2)卸下第一幀

輸入

ffmpeg -y -i "720p50_mobcal_ter.mpg" -an -f mpeg2video -vf select=gte(n\,1) "CUT-720p50_mobcal_ter.mpg" 

輸出

ffmpeg version N-76684-g1fe82ab Copyright (c) 2000-2015 the FFmpeg developers 
    built with gcc 5.2.0 (GCC) 
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib 
    libavutil  55. 6.100/55. 6.100 
    libavcodec  57. 15.100/57. 15.100 
    libavformat 57. 14.100/57. 14.100 
    libavdevice 57. 0.100/57. 0.100 
    libavfilter  6. 15.100/6. 15.100 
    libswscale  4. 0.100/4. 0.100 
    libswresample 2. 0.101/2. 0.101 
    libpostproc 54. 0.100/54. 0.100 
Input #0, mpegvideo, from '720p50_mobcal_ter.mpg': 
    Duration: N/A, bitrate: N/A 
    Stream #0:0: Video: mpeg2video (Main), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], max. 104857 kb/s, 50 fps, 50 tbr, 1200k tbn, 100 tbc 
Output #0, mpeg2video, to 'CUT-720p50_mobcal_ter.mpg': 
    Metadata: 
    encoder   : Lavf57.14.100 
    Stream #0:0: Video: mpeg2video, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 50 fps, 50 tbn, 50 tbc 
    Metadata: 
     encoder   : Lavc57.15.100 mpeg2video 
Stream mapping: 
    Stream #0:0 -> #0:0 (mpeg2video (native) -> mpeg2video (native)) 
Press [q] to stop, [?] for help 
frame= 255 fps=0.0 q=31.0 size= 2781kB time=00:00:05.10 bitrate=4467.3kbits/frame= 503 fps=0.0 q=31.0 Lsize= 4415kB time=00:00:10.08 bitrate=3588.5kbits/s 
video:4415kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000% 

3)的幀差

輸入

ffmpeg -y -i "720p50_mobcal_ter.avi" -i "CUT-720p50_mobcal_ter.mpg" -filter_complex "blend=all_mode=difference,hue=s=0" -c:v libx264 -crf 18 -c:a copy "DIFF-720p50_mobcal_ter.mpg" 

輸出

ffmpeg version N-76684-g1fe82ab Copyright (c) 2000-2015 the FFmpeg developers 
    built with gcc 5.2.0 (GCC) 
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib 
    libavutil  55. 6.100/55. 6.100 
    libavcodec  57. 15.100/57. 15.100 
    libavformat 57. 14.100/57. 14.100 
    libavdevice 57. 0.100/57. 0.100 
    libavfilter  6. 15.100/6. 15.100 
    libswscale  4. 0.100/4. 0.100 
    libswresample 2. 0.101/2. 0.101 
    libpostproc 54. 0.100/54. 0.100 
Input #0, avi, from '720p50_mobcal_ter.avi': 
    Metadata: 
    encoder   : Lavf57.14.100 
    Duration: 00:00:10.08, start: 0.000000, bitrate: 552974 kb/s 
    Stream #0:0: Video: rawvideo (I420/0x30323449), yuv420p, 1280x720, 554059 kb/s, SAR 1:1 DAR 16:9, 50 fps, 50 tbr, 50 tbn, 50 tbc 
Input #1, mpegvideo, from 'CUT-720p50_mobcal_ter.mpg': 
    Duration: N/A, bitrate: N/A 
    Stream #1:0: Video: mpeg2video (Main), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], max. 104857 kb/s, 50 fps, 50 tbr, 1200k tbn, 100 tbc 
[libx264 @ 000002784dbeb980] using SAR=1/1 
[libx264 @ 000002784dbeb980] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2 
[libx264 @ 000002784dbeb980] profile High, level 3.2 
[mpeg @ 000002784dbeaf20] VBV buffer size not set, using default size of 130KB 
If you want the mpeg file to be compliant to some specification 
Like DVD, VCD or others, make sure you set the correct buffer size 
Output #0, mpeg, to 'D:\DOWNLOADS\TMP\Video TDI\AVI\DIFF-720p50_mobcal_ter.mpg': 
    Metadata: 
    encoder   : Lavf57.14.100 
    Stream #0:0: Video: h264 (libx264), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 50 fps, 90k tbn, 50 tbc (default) 
    Metadata: 
     encoder   : Lavc57.15.100 libx264 
Stream mapping: 
    Stream #0:0 (rawvideo) -> blend:top 
    Stream #1:0 (mpeg2video) -> blend:bottom 
    hue -> Stream #0:0 (libx264) 
Press [q] to stop, [?] for help 
frame= 504 fps= 39 q=-1.0 Lsize= 32182kB time=00:00:10.04 bitrate=26258.5kbits/s 
video:32061kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.377054% 
[libx264 @ 000002784dbeb980] frame I:30 Avg QP:19.69 size:149974 
[libx264 @ 000002784dbeb980] frame P:299 Avg QP:23.28 size: 69423 
[libx264 @ 000002784dbeb980] frame B:175 Avg QP:24.48 size: 43280 
[libx264 @ 000002784dbeb980] consecutive B-frames: 30.6% 69.4% 0.0% 0.0% 
[libx264 @ 000002784dbeb980] mb I I16..4: 18.3% 51.4% 30.4% 
[libx264 @ 000002784dbeb980] mb P I16..4: 0.6% 5.6% 2.4% P16..4: 35.9% 22.9% 15.6% 0.0% 0.0% skip:17.0% 
[libx264 @ 000002784dbeb980] mb B I16..4: 0.2% 0.5% 0.3% B16..8: 49.5% 12.4% 5.6% direct:15.5% skip:16.1% L0:47.8% L1:42.1% BI:10.1% 
[libx264 @ 000002784dbeb980] 8x8 transform intra:57.5% inter:38.5% 
[libx264 @ 000002784dbeb980] coded y,uvDC,uvAC intra: 90.7% 0.0% 0.0% inter: 50.3% 0.0% 0.0% 
[libx264 @ 000002784dbeb980] i16 v,h,dc,p: 32% 23% 35% 10% 
[libx264 @ 000002784dbeb980] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 11% 41% 7% 5% 6% 5% 6% 8% 
[libx264 @ 000002784dbeb980] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 14% 23% 8% 7% 7% 7% 7% 8% 
[libx264 @ 000002784dbeb980] i8c dc,h,v,p: 100% 0% 0% 0% 
[libx264 @ 000002784dbeb980] Weighted P-Frames: Y:33.8% UV:0.0% 
[libx264 @ 000002784dbeb980] ref P L0: 58.1% 16.3% 14.2% 9.4% 2.0% 
[libx264 @ 000002784dbeb980] ref B L0: 79.3% 20.7% 
[libx264 @ 000002784dbeb980] kb/s:26056.02 

第二個命令使一切工作,而第二個在第一部分沒有(一個與-ss選項)所以我可以很高興,但我不確定是否爲每個視頻複製了第一幀,或者如果它是強制的t與我現在使用的相關,所以最好從具有相同幀數的壓縮視頻開始。

所以讓我們來看一個最後的問題:爲什麼FFMPEG在壓縮視頻的開頭添加了一個重複的第一幀,我該如何避免這種情況?

+1

我們如何重現這個問題?請包含第一條命令的完整控制檯輸出。 – LordNeckbeard

+0

爲什麼你想要控制檯輸出的幀差別命令是問題在別處?問題在於壓縮視頻比參考幀多一幀,所以比較之前就是這樣。如果兩個視頻的幀數不同,問題是如何進行比較。 – StepTNT

+0

你的問題對我來說不是很清楚,所以我認爲'ffmpeg'是添加了灰色框架。這是不是真的?無論如何,您應該始終使用您展示的任何'ffmpeg'命令來顯示完整的控制檯輸出。 – LordNeckbeard

回答

0

編碼與

ffmpeg -i "720p50_mobcal_ter.avi" -c:v mpeg2video "720p50_mobcal_ter.mpg" 

,而不是

ffmpeg -i "720p50_mobcal_ter.avi" -an -f mpeg2video -y "720p50_mobcal_ter.mpg" 

防止重複框架的建立,使一切工作正常。