c# - When generating a video from images and adding audio the video isn't playable -
so have bunch of images in folder, following structure:
image-0.png image-1.png image-2.png
sometimes folder can have 1 image saved as:
image-0.png
my code generate video , add audio
// create file using (wavefilereader wf = new wavefilereader(audio)) { // files oldvideo = "old.avi"; newvideo = "video.avi"; audio = "sound.wav"; // time of audio , divide images time = wf.totaltime.totalseconds; mimtime = time / imagescount; ffmpegpath = "ffmpeg.exe"; ffmpegparams = " -r 1/" + mimtime + " -i " + imagesfolder + "image-%d.png -t " + time + " -y -vf scale=1280:-2 " + oldvideo; ffmaudioparams = " -i " + oldvideo + " -i " + audio + " -c copy -shortest " + newvideo; } using (process ffmpeg = new process()) { //generate video ffmpegstartinfo = new processstartinfo(); ffmpegstartinfo.filename = ffmpegpath; ffmpegstartinfo.arguments = ffmpegparams; ffmpegstartinfo.redirectstandardoutput = true; ffmpegstartinfo.redirectstandarderror = true; ffmpegstartinfo.useshellexecute = false; ffmpegstartinfo.createnowindow = true; ffmpeg.startinfo.filename = ffmpegpath; ffmpeg.startinfo.arguments = ffmpegparams; ffmpeg.startinfo = ffmpegstartinfo; ffmpeg.start(); ffmpeg.waitforexit(30000); /*ffmpeg.startinfo.filename = "cmd.exe"; ffmpeg.startinfo.arguments = "/k " + ffmpegpath + " " + ffmpegparams; ffmpeg.start(); ffmpeg.waitforexit(30000);*/ } using (process ffmaudio = new process()) { //add audio video ffmaudiostartinfo = new processstartinfo(); ffmaudiostartinfo.filename = ffmpegpath; ffmaudiostartinfo.arguments = ffmaudioparams; ffmaudiostartinfo.redirectstandardoutput = true; ffmaudiostartinfo.redirectstandarderror = true; ffmaudiostartinfo.useshellexecute = false; ffmaudiostartinfo.createnowindow = true; ffmaudio.startinfo.filename = ffmpegpath; ffmaudio.startinfo.arguments = ffmaudioparams; ffmaudio.startinfo = ffmaudiostartinfo; ffmaudio.start(); ffmaudio.waitforexit(30000); /*ffmaudio.startinfo.filename = "cmd.exe"; ffmaudio.startinfo.arguments = "/k " + ffmpegpath + " " + ffmaudioparams; ffmaudio.start(); ffmaudio.waitforexit(30000);*/ }
so, code does, wavfilereader
gets total length of audio file, , splits time number of images have, can generate video images split equally. generate video file called 'old.avi', used wav file generate new file called video.avi (which trying have generated video , audio together)
my problem when generate video becomes uplayable. claims (for example) 1 minute 50 seconds long, once click it, won't play. becomes unplayable, can see below
http://i.imgur.com/tsck2nx.gifv
i using c# process , winforms, opens cmd line run ffmpeg, 2 commands called above named variables below:
ffmpegparams; ffmaudioparams;
which has commands using
-r 1/ (audio length /divided total images) they're equal -t (to limit total time audio's total seconds) ... using more can see in code above
how can fix problem, have described?
cmd line when generating video:
ffmpeg version n-86848-g03a9e6f copyright (c) 2000-2017 ffmpeg developers built gcc 7.1.0 (gcc) configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib libavutil 55. 68.100 / 55. 68.100 libavcodec 57.102.100 / 57.102.100 libavformat 57. 76.100 / 57. 76.100 libavdevice 57. 7.100 / 57. 7.100 libavfilter 6. 95.100 / 6. 95.100 libswscale 4. 7.101 / 4. 7.101 libswresample 2. 8.100 / 2. 8.100 libpostproc 54. 6.100 / 54. 6.100 input #0, image2, 'c:\users\laptop\documents\program/images/image-%d.png': duration: 00:00:00.04, start: 0.000000, bitrate: n/a stream #0:0: video: png, rgba(pc), 800x800, 25 tbr, 25 tbn, 25 tbc stream mapping: stream #0:0 -> #0:0 (png (native) -> mpeg4 (native)) press [q] stop, [?] [mpeg4 @ 00000000024f44a0] bitrate tolerance 4000000 small bitrate 200000, overriding output #0, avi, 'c:\users\laptop\documents\program/old.avi': metadata: isft : lavf57.76.100 stream #0:0: video: mpeg4 (fmp4 / 0x34504d46), yuv420p, 1280x1280, q=2-31, 200 kb/s, 0.01 fps, 0.01 tbn, 0.01 tbc metadata: encoder : lavc57.102.100 mpeg4 side data: cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 frame= 1 fps=0.0 q=6.8 lsize= 46kb time=00:01:37.57 bitrate= 3.9kbits/s speed=1.43e+003x video:41kb audio:0kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 13.641467%
when adding audio video
ffmpeg version n-86848-g03a9e6f copyright (c) 2000-2017 ffmpeg developers built gcc 7.1.0 (gcc) configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib libavutil 55. 68.100 / 55. 68.100 libavcodec 57.102.100 / 57.102.100 libavformat 57. 76.100 / 57. 76.100 libavdevice 57. 7.100 / 57. 7.100 libavfilter 6. 95.100 / 6. 95.100 libswscale 4. 7.101 / 4. 7.101 libswresample 2. 8.100 / 2. 8.100 libpostproc 54. 6.100 / 54. 6.100 input #0, avi, 'c:\users\laptop\documents\program/old.avi': metadata: encoder : lavf57.76.100 duration: 00:01:37.58, start: 0.000000, bitrate: 3 kb/s stream #0:0: video: mpeg4 (simple profile) (fmp4 / 0x34504d46), yuv420p, 1280x1280 [sar 1:1 dar 1:1], 0.01 fps, 0.01 tbr, 0.01 tbn, 40 tbc guessed channel layout input stream #1.0 : mono input #1, wav, 'c:\users\laptop\documents\program/audio.wav': duration: 00:01:37.57, bitrate: 352 kb/s stream #1:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 hz, mono, s16, 352 kb/s output #0, avi, 'c:\users\laptop\documents\program/video.avi': metadata: isft : lavf57.76.100 stream #0:0: video: mpeg4 (simple profile) (fmp4 / 0x34504d46), yuv420p, 1280x1280 [sar 1:1 dar 1:1], q=2-31, 0.01 fps, 0.01 tbr, 0.01 tbn, 0.01 tbc stream #0:1: audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 hz, mono, s16, 352 kb/s stream mapping: stream #0:0 -> #0:0 (copy) stream #1:0 -> #0:1 (copy) press [q] stop, [?] frame= 1 fps=0.0 q=-1.0 lsize= 55kb time=00:01:37.57 bitrate= 4.6kbits/s speed=1.95e+005x video:41kb audio:4kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 21.946869%
a few things:
1) check calculations. output shows,
frame= 1 fps=0.0 q=-1.0 lsize= 55kb time=00:01:37.57
at 0.01 fps, image switch on after 100 seconds. since output 97 seconds, there's 1 frame , 1 image in output. although input shows single image input:
input #0, image2, 'c:\users\laptop\documents\program/images/image-%d.png': duration: 00:00:00.04, start: 0.000000, bitrate: n/a
(use -framerate
instead of -r
)
2) vlc , other players don't low framerates. add -r 6
after scale filter. should duration display in vlc.
Comments
Post a Comment