I want to extract the audio stream of an avi file as a wav file, it works but it is really slow (~4-5fps) although I just want to copy the stream.
Here is the type of stream I want to extract (ffprobe info):
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Going through AviSynth does it about 100 times faster, but I would prefer a pure FFmpeg solution. Why such a speed difference? It looks like FFmpeg is reading and processing through the whole file whereas AviSynth can just extract the data without reading it.
Example:
ffmpeg -i file.avi -vn -ac 2 -c:a copy audio.wav
or
ffmpeg -i file.avi -map 0:a -ac 2 -c:a copy audio.wav
both work fine but take time.
Using an AviSynth script as input:
ffmpeg -i script.avs -map 0:a -ac 2 -c:a copy audio.wav
with script.avs containing just:
AviSource("file.avi")
does the same but almost instantaneously!
Any idea why AviSynth is so much faster and if there is a way to get the same speed in FFmpeg?
Edit: adding logs
Using FFmpeg directly:
E:\>ffmpeg -i "file.avi" -map 0:a -c:a copy -y -benchmark "output.wav"
ffmpeg version N-92936-ged3b64402e Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181201
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --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-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 25.100 / 56. 25.100
libavcodec 58. 43.100 / 58. 43.100
libavformat 58. 25.100 / 58. 25.100
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 47.100 / 7. 47.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
[avi # 0000018d3c38a680] non-interleaved AVI
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, avi, from 'file.avi':
Duration: 00:18:37.49, start: 0.000000, bitrate: 534682 kb/s
Stream #0:0: Video: rawvideo, bgr24, 1280x720, 533183 kb/s, 24.11 fps, 24.11 tbr, 24.10 tbn, 24.10 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Output #0, wav, to 'output.wav':
Metadata:
ISFT : Lavf58.25.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 192445kB time=00:18:37.12 bitrate=1411.2kbits/s speed=4.77x
video:0kB audio:192445kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000040%
bench: utime=1.188s stime=50.766s rtime=234.254s
bench: maxrss=17468kB
Using AviSynth:
E:\>ffmpeg -i "soundout.avs" -map 0:a -c:a copy -y -benchmark "output.wav"
ffmpeg version N-92936-ged3b64402e Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181201
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --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-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 25.100 / 56. 25.100
libavcodec 58. 43.100 / 58. 43.100
libavformat 58. 25.100 / 58. 25.100
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 47.100 / 7. 47.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, avisynth, from 'soundout.avs':
Duration: 00:18:37.49, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (BGR[24] / 0x18524742), bgr24, 1280x720, 24.11 fps, 24.11 tbr, 24.10 tbn, 24.10 tbc
Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Output #0, wav, to 'output.wav':
Metadata:
ISFT : Lavf58.25.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 192445kB time=00:18:37.11 bitrate=1411.2kbits/s speed= 155x
video:0kB audio:192445kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000040%
bench: utime=0.234s stime=1.047s rtime=7.236s
bench: maxrss=23792kB
Edit: tests after "reencoding" AVI file:
Onto something...
Say my original file is f.avi. Here is ffprobe's results:
[avi # 0x55a9c4b1e740] non-interleaved AVI
Input #0, avi, from 'f.avi':
Duration: 00:00:38.18, start: 0.000000, bitrate: 1104582 kb/s
Stream #0:0: Video: rawvideo, bgr24, 1632x1200, 1104265 kb/s, 23.47 fps, 23.47 tbr, 23.47 tbn, 23.47 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
Extracting audio takes a long time.
Now if I "reencode" the file in another AVI:
ffmpeg -i f.avi -c copy f2.avi
I can extract the audio from f2.avi in milliseconds!
FFprobe on f2.avi:
Input #0, avi, from 'f2.avi':
Metadata:
encoder : Lavf57.56.101
Duration: 00:00:38.18, start: 0.000000, bitrate: 1104456 kb/s
Stream #0:0: Video: rawvideo, bgr24, 1632x1200, 1104265 kb/s, 23.47 fps, 23.47 tbr, 23.47 tbn, 23.47 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
It's the same apart from the Metadata, which shouldn't make a difference, but with this comparison I see the problem must have to do with the fact that the original is non-interleaved!
I would assume it was easier to read and extract the audio from a non-interleaved file but maybe this is not conforming to AVI standards, hence the extra work needed?
You answered your question yourself: It looks like you are input bandwidth bottlenecked and ffmpeg reads the raw video just to throw it away, while avisynth (which will probably use the AVI Splitter from DirectShow) only reads the audio data from disk. I don't see a way to make ffmpeg do the same.
Related
I am trying to run the following command :
-i "2020_11_30_03_37_37.mp4" -i "2020_11_30_03_37_44.jpg" -f lavfi -t 6.016 -i anullsrc -filter_complex "[0:v]crop=544:544:0:208,boxblur=luma_radius=10:chroma_radius=10:luma_power=1,scale=1080:1080[bg];[0:v]scale=612:1080[fg];[bg][fg]overlay=234:0:shortest=1[si];[si]trim=0:1,setpts=(PTS-STARTPTS)*2[video0];[0:a]atrim=0:1,asetpts=PTS-STARTPTS,atempo=0.5[audio0];[si]trim=1:5.016,setpts=(PTS-STARTPTS)*1[video1];[0:a]atrim=1:5.016,asetpts=PTS-STARTPTS,atempo=1[audio1];[video0][audio0][video1][audio1]concat=n=2:v=1:a=1[mv];[1:v]scale=428:-1[sticker1];[mv][sticker1]overlay=x=0:y=0:enable='between(t,0,1)'" "2020_11_30_03_37_50.mp4"
but FFmpeg throwing the following error:
Invalid stream specifier: si.
but I already specified this stream in command. unable to understand what's wrong
here is the log
C:\Users\abhis\AppData\Local\Packages\64815ZMobileApps.VideoDownloaderforYouTubeDownload_61cxy7b35vdsg\TempState>ffmpeg -i "2020_11_30_03_37_37.mp4" -i "2020_11_30_03_37_44.jpg" -f lavfi -t 6.016 -i anullsrc -filter_complex "[0:v]crop=544:544:0:208,boxblur=luma_radius=10:chroma_radius=10:luma_power=1,scale=1080:1080[bg];[0:v]scale=612:1080[fg];[bg][fg]overlay=234:0:shortest=1[si];[si]trim=0:1,setpts=(PTS-STARTPTS)*2[video0];[0:a]atrim=0:1,asetpts=PTS-STARTPTS,atempo=0.5[audio0];[si]trim=1:5.016,setpts=(PTS-STARTPTS)*1[video1];[0:a]atrim=1:5.016,asetpts=PTS-STARTPTS,atempo=1[audio1];[video0][audio0][video1][audio1]concat=n=2:v=1:a=1[mv];[1:v]scale=428:-1[sticker1];[mv][sticker1]overlay=x=0:y=0:enable='between(t,0,1)'" "2020_11_30_03_37_50.mp4"
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.1 (GCC) 20200726
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-libsrt --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-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2020_11_30_03_37_37.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:05.02, start: 0.000000, bitrate: 2097 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 544x960, 1997 kb/s, SAR 1:1 DAR 17:30, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
Metadata:
handler_name : SoundHandle
Input #1, image2, from '2020_11_30_03_37_44.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 2416762 kb/s
Stream #1:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1280x854 [SAR 200:200 DAR 640:427], 25 tbr, 25 tbn, 25 tbc
Input #2, lavfi, from 'anullsrc':
Duration: N/A, start: 0.000000, bitrate: 705 kb/s
Stream #2:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
[mov,mp4,m4a,3gp,3g2,mj2 # 00000279fa82eb80] Invalid stream specifier: si.
Last message repeated 1 times
Stream specifier 'si' in filtergraph description [0:v]crop=544:544:0:208,boxblur=luma_radius=10:chroma_radius=10:luma_power=1,scale=1080:1080[bg];[0:v]scale=612:1080[fg];[bg][fg]overlay=234:0:shortest=1[si];[si]trim=0:1,setpts=(PTS-STARTPTS)*2[video0];[0:a]atrim=0:1,asetpts=PTS-STARTPTS,atempo=0.5[audio0];[si]trim=1:5.016,setpts=(PTS-STARTPTS)*1[video1];[0:a]atrim=1:5.016,asetpts=PTS-STARTPTS,atempo=1[audio1];[video0][audio0][video1][audio1]concat=n=2:v=1:a=1[mv];[1:v]scale=428:-1[sticker1];[mv][sticker1]overlay=x=0:y=0:enable='between(t,0,1)' matches no streams.
You can't re-use labels (a.k.a. "pads", unintuitively) from filter outputs. So you can't use si more than once.
Add the split filter to make copies:
-i "2020_11_30_03_37_37.mp4" -i "2020_11_30_03_37_44.jpg" -f lavfi -t 6.016 -i anullsrc -filter_complex "[0:v]crop=544:544:0:208,boxblur=luma_radius=10:chroma_radius=10:luma_power=1,scale=1080:1080[bg];[0:v]scale=612:1080[fg];[bg][fg]overlay=234:0:shortest=1,split=outputs=2[si1][si2];[si1]trim=0:1,setpts=(PTS-STARTPTS)*2[video0];[0:a]atrim=0:1,asetpts=PTS-STARTPTS,atempo=0.5[audio0];[si2]trim=1:5.016,setpts=(PTS-STARTPTS)*1[video1];[0:a]atrim=1:5.016,asetpts=PTS-STARTPTS,atempo=1[audio1];[video0][audio0][video1][audio1]concat=n=2:v=1:a=1[mv];[1:v]scale=428:-1[sticker1];[mv][sticker1]overlay=x=0:y=0:enable='between(t,0,1)'" "2020_11_30_03_37_50.mp4"
I often shoot films with several audio inputs, resulting in video files with multiple audio tracks supposed to be played all together at the same time.
I usually go through editing those files and there I do whatever I want with those files, but sometimes I would also like to just send the files right away online without editing, in which case I would enjoy FFMPEG's fast & simple & quality encoding.
But here's the catch: most online video streaming services don't support multiple audio tracks, so I have to merge them into one so we can hear everything.
I also want to upscale the video (it's a little trick for the streaming service to trigger its higher quality encoding).
And finally, since it's just an encoding meant to just be shared on a streaming service, I prefer a fast & light encoding over quality, which HEVC NVENC is good for.
So far I've tried to use the amix advanced filter and I try to use the Lanczos filter for upscaling which seems to give a better result in my case.
The input file is quite simple:
Stream 0:0 : video track
Stream 0:1 : main audio recording
Stream 0:2 : secondary audio recording
The audio tracks are at the correct volume and duration and position in time, so the only thing I need is really just to turn them into one track
ffmpeg -i "ow_raw.mp4" -filter_complex "[0:1][0:2]amix=inputs=2[a]" -map "0:0" -map "[a]" -c:v hevc_nvenc -preset fast -level 4.1 -pix_fmt yuv420p -vf scale=2560:1:flags=lanczos "ow_share.mkv" -y
But it doesn't work:
ffmpeg version N-94905-g8efc9fcc56 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.1.1 (GCC) 20190807
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. 35.100 / 56. 35.100
libavcodec 58. 56.101 / 58. 56.101
libavformat 58. 32.104 / 58. 32.104
libavdevice 58. 9.100 / 58. 9.100
libavfilter 7. 58.102 / 7. 58.102
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'ow_raw.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2019-11-02T16:43:32.000000Z
date : 2019
Duration: 00:15:49.79, start: 0.000000, bitrate: 30194 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt470m), 1920x1080 [SAR 1:1 DAR 16:9], 29805 kb/s, 60 fps, 60 tbr, 90k tbn, 120 tbc (default)
Metadata:
creation_time : 2019-11-02T16:43:32.000000Z
handler_name : VideoHandle
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 196 kb/s (default)
Metadata:
creation_time : 2019-11-02T16:43:32.000000Z
handler_name : SoundHandle
Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 184 kb/s (default)
Metadata:
creation_time : 2019-11-02T16:43:32.000000Z
handler_name : SoundHandle
Stream mapping:
Stream #0:1 (aac) -> amix:input0 (graph 0)
Stream #0:2 (aac) -> amix:input1 (graph 0)
Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))
amix (graph 0) -> Stream #0:1 (libvorbis)
Press [q] to stop, [?] for help
[hevc_nvenc # 000002287e34a040] InitializeEncoder failed: invalid param (8)
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!
I'm merging a video (recorded with ffmpeg, good quality, all solid), with a musicfile.mp3. However every couple of seconds the music stutters and skips slightly. Which seems very strange since simply adding music on top of a video sounds like the engine could relax and take its time, creating no artifacts. (In comparison to recording live desktop footage). Can anyone help me sort this out?
System: MacOS MBP 2015, 16gb ram 2.7ghz i5
ffmpeg -i "temp/1561246948349.mkv" -i "music/happy.mp3" -vcodec copy -filter_complex amix -map 0:v -map 0:a -map 1:a -shortest -b:a 144k "finished/2019-06-22/1561246948349/output.mkv"
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.3_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, matroska,webm, from 'temp/1561246948349.mkv':
Metadata:
ENCODER : Lavf58.20.100
Duration: 00:00:21.50, start: 0.000000, bitrate: 5834 kb/s
Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv422p(progressive), 2880x1800, 30 fps, 30 tbr, 1k tbn, 2000k tbc (default)
Metadata:
ENCODER : Lavc58.35.100 libx264
DURATION : 00:00:21.467000000
Stream #0:1: Audio: vorbis, 44100 Hz, stereo, fltp (default)
Metadata:
ENCODER : Lavc58.35.100 libvorbis
DURATION : 00:00:21.496000000
Input #1, mp3, from 'music/happy.mp3':
Metadata:
album : Random
genre : Jazz & Blues
Duration: 00:15:59.84, start: 0.025057, bitrate: 186 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 186 kb/s
Metadata:
encoder : LAME3.100
Stream mapping:
Stream #0:1 (vorbis) -> amix:input0
Stream #1:0 (mp3float) -> amix:input1
amix -> Stream #0:0 (libvorbis)
Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
Output #0, matroska, to 'finished/2019-06-22/1561246948349/output.mkv':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 44100 Hz, stereo, fltp, 144 kb/s (default)
Metadata:
encoder : Lavc58.35.100 libvorbis
Stream #0:1: Video: h264 (High 4:4:4 Predictive) (H264 / 0x34363248), yuv422p(progressive), 2880x1800, q=2-31, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Metadata:
ENCODER : Lavc58.35.100 libx264
DURATION : 00:00:21.467000000
frame= 640 fps=0.0 q=-1.0 Lsize= 15227kB time=00:00:21.46 bitrate=5810.3kbits/s speed=33.8x
video:14888kB audio:318kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: 0.139864%
I can extract the frames using below ffmpeg but it comes out 720x576 square pixel instead of anamorphic non-square 1024x576. How do I output 720x576 rectangle pixel as shown on TV?
How do i deinterlace the frames as output is interlaced?
ffmpeg -i Midnight.vob -vf fps=1,setdar=16:9 -q:v 2 Midnight%06d.jpg
How do i deal with this below in ffmpeg.
[swscaler # 0000000002a8ec40] deprecated pixel format used, make sure
you did set range correctly. Video: mjpeg, yuvj420p(pc).
Am I to understand that the video colour format is out of date and that (pc) is the range 0-255 for colours?
ffmpeg -i Midnight.vob -vf fps=1,setdar=16:9 -q:v 2 Midnight%06d.jpg ffmpeg version N-93828-g68bac50604 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.3.1 (GCC) 20190414 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-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56. 26.101 / 56. 26.101 libavcodec 58. 52.101 / 58.
52.101 libavformat 58. 27.103 / 58. 27.103 libavdevice 58. 7.100 / 58. 7.100 libavfilter 7. 50.100 / 7. 50.100 libswscale 5. 4.100 / 5. 4.100 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 Input #0, mpeg, from 'Midnight.vob': Duration: 00:42:04.58, start: 0.287267, bitrate: 5829 kb/s
Stream #0:0[0x1bf]: Data: dvd_nav_packet
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:2[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:3[0x81]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:4[0x82]: Audio: ac3, 48000 Hz, mono, fltp, 192 kb/s
Stream #0:5[0x22]: Subtitle: dvd_subtitle
Stream #0:6[0x24]: Subtitle: dvd_subtitle
Stream #0:7[0x25]: Subtitle: dvd_subtitle
Stream #0:8[0x26]: Subtitle: dvd_subtitle
Stream #0:9[0x28]: Subtitle: dvd_subtitle
Stream #0:10[0x21]: Subtitle: dvd_subtitle
Stream #0:11[0x23]: Subtitle: dvd_subtitle Stream mapping: Stream #0:1 -> #0:0 (mpeg2video (native) -> mjpeg (native)) Press [q] to stop, [?] for help [swscaler # 000000000295ec40] deprecated pixel format used, make sure you did set range correctly Output #0, image2, to 'Midnight%06d.jpg': Metadata:
encoder : Lavf58.27.103
Stream #0:0: Video: mjpeg, yuvj420p(pc), 720x576 [SAR 36:5 DAR 9:1], q=2-31, 200 kb/s, 1 fps, 1 tbn, 1 tbc
Metadata:
encoder : Lavc58.52.101 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 [mpeg # 0000000000400340] New subtitle stream 0:12 at pos:7458830 and DTS:12.4873s [mpeg # 0000000000400340] New subtitle stream 0:13 at pos:7475214 and DTS:12.4873s frame= 951 fps=115 q=2.0 Lsize=N/A time=00:15:51.00 bitrate=N/A speed= 115x
video:49190kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Settled on for large jpg to render then shrink to 1024x576. If deinterlace remove yadif=1.
ffmpeg -i input.vob -vf yadif=1,scale=4096x2304,setdar=16:9 -qmin 1 -q:v 1 output%06d.jpg
Jpg is original size 1024x576 square pixel.
ffmpeg -i input.vob -vf yadif=1,fps=1,scale=iw*sar:ih,setsar=1 -qmin 1 -q:v 1 output%06d.jpg
Png gives better quality over jpg.
Thanks for your contributions.
I had to reinstall windows 10 because windows. I have this exact same code working prior to the reinstall, however after I cant get it to work.
I am using the latest nvidia drivers 416.16
I have VisualStudio and Cuda Toolkit installed
2x 1080TIs
Using ffmpeg 4.0.2:
T:\ffmpeg\bin\4.0.2\ffmpeg.exe -c:v h264_cuvid -i "T:\Streams\01-ready\2018-10-10 21-19-21.mp4" -i "T:\Streams\10-source\kpg-logo.png" -filter_complex "overlay=10:10" -b:v 24000k -c:v h264_nvenc -c:a copy "T:\Streams\02-encoded\2018-10-10 21-19-21_watermarked.mp4"
Output:
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.1 (GCC) 20180722
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --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-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'T:\Streams\01-ready\2018-10-10 21-19-21.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.84.100
Duration: 00:28:41.71, start: 0.000000, bitrate: 24422 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown), 2560x1440, 24130 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 286 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, png_pipe, from 'T:\Streams\10-source\kpg-logo.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 2560x1440 [SAR 2834:2834 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 (h264_cuvid) -> overlay:main
Stream #1:0 (png) -> overlay:overlay
overlay -> Stream #0:0 (h264_nvenc)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264_nvenc # 000002851a001940] CreateInputBuffer failed: out of memory (10)
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!
Press any key to continue . . .
Error Message
[h264_nvenc # 000002851a001940] CreateInputBuffer failed: out of memory (10)
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!
Press any key to continue . . .
Any ideas?
EDIT:
Still having issues, now even with the simple commands:
ffmpeg.exe -y -hwaccel cuvid -c:v h264_cuvid -i "input" -c:v h264_nvenc -preset slow "output.mp4"
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.1 (GCC) 20180722
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --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-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'T:\Streams\01-ready\2018-10-15 20-49-44.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.84.100
Duration: 00:00:10.64, start: 0.000000, bitrate: 22978 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/unknown/unknown), 2560x1440, 24216 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 156 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (h264_cuvid) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, mp4, to 'T:\Streams\02-encoded\2018-10-15 20-49-44.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Stream #0:0(und): Video: h264 (h264_nvenc) (Main) (avc1 / 0x31637661), cuda, 2560x1440 [SAR 1:1 DAR 16:9], q=-1--1, 2000 kb/s, 60 fps, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.18.100 h264_nvenc
Side data:
cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: -1
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.18.100 aac
[h264_cuvid # 000001a99033b600] ctx->cvdl->cuvidMapVideoFrame(ctx->cudecoder, parsed_frame.dispinfo.picture_index, &mapped_frame, &pitch, ¶ms) failed -> CUDA_ERROR_UNKNOWN: unknown error
Error while decoding stream #0:0: Generic error in an external library
/* repeated many many times */
[h264_nvenc # 000001a98fcfc100] Failed locking bitstream buffer: invalid param (8)
video encoding failed: Invalid argument
[aac # 000001a98fdcd380] Qavg: 64894.355
[aac # 000001a98fdcd380] 2 frames left in the queue on closing
Conversion failed!
Press any key to continue . . .
Full windows batch file:
#echo off
set ffmpegversion=20181015-c27c7b4-win64-static
set sourcedir=T:\Streams\01-ready
set outputdir=T:\Streams\02-encoded
set finaldir=T:\ffmpeg\mp4-upload
set libdir=T:\ffmpeg\bin\%ffmpegversion%
set introvid=T:\Streams\10-source\kpg-intro-10pec-audio.mp4
set watermark=T:\Streams\10-source\kpg-logo.png
set introvidlen=3.00
set outputbitrate=24000
cd /d %libdir%
if not exist %outputdir% (
mkdir %outputdir%
)
if not exist %finaldir% (
mkdir %finaldir%
)
setlocal enabledelayedexpansion
#echo Checking %sourcedir%\*.mp4
for %%f in (%sourcedir%\*.mp4) do (
if not exist "%outputdir%\%%~nf_watermarked.mp4" (
%libdir%\ffmpeg.exe -i "%%f" -i "%watermark%" -filter_complex "overlay=0:0" -b:v %outputbitrate%k -s 2560x1440 -pix_fmt yuv420p -c:a copy "%outputdir%\%%~nf_watermarked.mp4"
TIMEOUT 2
)
if not exist "%outputdir%\%%~nf_watermarked_ready.mp4" (
%libdir%\ffmpeg.exe -i "%introvid%" -i "%outputdir%\%%~nf_watermarked.mp4" -an -filter_complex " [0:v]trim=start=0:end=%introvidlen%,setpts=PTS-STARTPTS[firstclip]; [1:v]trim=start=1,setpts=PTS-STARTPTS[secondclip]; [0:v]trim=start=%introvidlen%,setpts=PTS-STARTPTS[fadeoutsrc]; [1:v]trim=start=0:end=1,setpts=PTS-STARTPTS[fadeinsrc]; [fadeinsrc]format=pix_fmts=yuva420p, fade=t=in:st=0:d=1:alpha=1[fadein]; [fadeoutsrc]format=pix_fmts=yuva420p, fade=t=out:st=0:d=1:alpha=1[fadeout]; [fadein]fifo[fadeinfifo]; [fadeout]fifo[fadeoutfifo];[fadeoutfifo][fadeinfifo]overlay[crossfade]; [firstclip][crossfade][secondclip]concat=n=3[output]; [0:a][1:a] acrossfade=d=1 [audio]" -map "[output]" -map "[audio]" -c:v libx264 -c:a aac -b:v %outputbitrate%k -ar 44100 -ab 96k -sn "%outputdir%\%%~nf_watermarked_ready.mp4"
TIMEOUT 2
)
if not exist "%finaldir%\%%~nf.mp4" (
COPY "%outputdir%\%%~nf_watermarked_ready.mp4" "%finaldir%\%%~nf.mp4"
TIMEOUT 2
)
)
PAUSE
Experienced similar results when other processes were running that had access the the video card. Just having the programs open(not actively encoding or otherwise requiring hardware acceleration) caused a conflict.