我正在尝试移植这个例子关于如何使用 ffmpeg 和调色板制作 gif,特别是我不想要临时文件
我现在的代码是
p1 = subprocess.Popen(["ffmpeg", "-ss", "00:00:00", "-t", "3", "-i", video['url'], "-vf", "fps=15,scale=320:-1:flags=lanczos,palettegen", "-f", "image2pipe", "-vcodec", "ppm", "-"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["ffmpeg", "-ss", "00:00:00", "-t", "3", "-i", video['url'], "-filter_complex", "fps=15,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse", "-f", "gif", "-"], stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close()
return Response(p2.communicate()[0])
但FFMPEG
一直输出这个错误Invalid file index 1 in filtergraph description fps=15,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse.
完整输出为
ffmpeg version N-81995-gd790e48 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc
libavutil 55. 32.100 / 55. 32.100
libavcodec 57. 61.103 / 57. 61.103
libavformat 57. 52.100 / 57. 52.100
libavdevice 57. 0.102 / 57. 0.102
libavfilter 6. 64.100 / 6. 64.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 2.100 / 2. 2.100
libpostproc 54. 0.100 / 54. 0.100
ffmpeg version N-81995-gd790e48 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc
libavutil 55. 32.100 / 55. 32.100
libavcodec 57. 61.103 / 57. 61.103
libavformat 57. 52.100 / 57. 52.100
libavdevice 57. 0.102 / 57. 0.102
libavfilter 6. 64.100 / 6. 64.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 2.100 / 2. 2.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://r7---sn-p0n5jxaa-hxms.googlevideo.com/videoplayback?ratebypass=yes&fexp=9446761&initcwndbps=3813750&requiressl=yes&mime=video%2Fmp4&key=yt6&id=o-AD36_xl1KeAvc29f_HgjZkvtd3oEbO1YvtlBeOH5PyS5&pcm2cms=yes&mm=31&mn=sn-p0n5jxaa-hxms&ip=187.190.166.119&ms=au&mt=1477256307&gcr=mx&sparams=dur%2Cei%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&pl=26&ei=rCQNWJ-LCoGU_QH5vJGICQ&itag=22&source=youtube&upn=8O6fCp4J1Ww&ipbits=0&dur=4712.861&expire=1477277964&lmt=1471437242705377&mv=m&signature=1A503BE382045039B1FDB3D8BEA72C9C66A7A29F.979480BAE0921C278D1AC4744CF1CEAC68FF231A':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2016-08-17T12:26:42.000000Z
Duration: 01:18:32.81, start: 0.000000, bitrate: 319 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 190 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
creation_time : 2016-08-17T12:26:42.000000Z
handler_name : ISO Media file produced by Google Inc.
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
creation_time : 2016-08-17T12:26:42.000000Z
handler_name : ISO Media file produced by Google Inc.
Invalid file index 1 in filtergraph description fps=15,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse.
最后它生成了一个 gif,但是不能播放。
答案1
这调色板使用过滤器需要两个输入(主输入 + 调色板)。您只提供了主输入,而调色板缺失,因此[1:v]
引用了不存在的第二个输入。