Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Cannot join mp3 file and avi file with ffmpeg
13 novembre 2014, par RULE101I am using this code to join an mp3 file and video file with ffmpeg
ffmpeg -i /file1.mp3 -ab 128k -i /file2.avi -vcodec copy -f avi /file3.avi
But this code gives that error
Option ab (audio bitrate (please use -b:a)) cannot be applied to input file /file1.mp3 -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to. Error parsing options for input file /file1.mp3. Error opening input files: Invalid argument
How can i do this job ?
-
How to take snapshot with multiple web cameras at the same time using PHP in Centos ?
13 novembre 2014, par galengodisI'm trying to take still photos / snapshots with multiple web cameras at the same time through php / shell_execute.
This is what I use so I can the cameras in the background.
shell_exec('ffmpeg -f video4linux2 -s 1280x960 -i /dev/video0 -q:v 0 -b:v 10000k -vcodec mjpeg -vframes 1 /var/www/html/cam1.jpg -y > /dev/null 2>/dev/null &'); shell_exec('ffmpeg -f video4linux2 -s 1280x960 -i /dev/video1 -q:v 0 -b:v 10000k -vcodec mjpeg -vframes 1 /var/www/html/cam2.jpg -y > /dev/null 2>/dev/null &');
It outputs only one image from the cameras. If i run them one at a time with the same code everything works. Fyi the "&" at the end makes the php run in background. Read more here about shell_exec background process: Is there a way to use shell_exec without waiting for the command to complete?
> [root@localhost ~]# lsusb > Bus 001 Device 002: ID 8087:8000 Intel Corp. > Bus 002 Device 004: ID 1a40:0201 Terminus Technology Inc. FE 2.1 > 7-port Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root > hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus > 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 002 > Device 006: ID 046d:0825 Logitech, Inc. Webcam C270 Bus 002 Device > 005: ID 0c45:6340 Microdia > > [root@localhost ~]# find /dev/bus/ /dev/bus/ /dev/bus/usb > /dev/bus/usb/003 /dev/bus/usb/003/001 /dev/bus/usb/002 > /dev/bus/usb/002/006 /dev/bus/usb/002/005 /dev/bus/usb/002/004 > /dev/bus/usb/002/001 /dev/bus/usb/001 /dev/bus/usb/001/002 > /dev/bus/usb/001/001
I've tried with altering applications between ffmpeg and streamer. So the problem seems to be USB-related. The both cameras are plugged into a USB-hub (with an external power supply). The cameras are of different brands.
I'm on Centos 7, 64bit.
-
Why is my ffmpeg stream subprocess freezing at 6 minutes ?
13 novembre 2014, par nonlinearmindI have a ffmpeg pipeline in a shell script that is launched as a subprocess in Python. For some reason, when Python launches the script, my video streams perfectly and then freezes at about six minutes every time. After it freezes, if I tried to run the script manually, it gives me this error:
Invalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true Failed to symlink /root/.pulse/65f3ded611649c6dcf9ebae20000046d-runtime to /tmp/pulse-PKdhtXMmr18n: Input/output error [alsa @ 0x4b2f0] cannot open audio device hw:0,0 (Device or resource busy) hw:0,0: Input/output error
However, if I restart and run the script manually, the audio & video will play fine indefinitely.
Does anyone know why this is happening? Thanks.
Here is my pipline.sh file:
sudo ffmpeg -f video4linux2 -video_size 640x480 -framerate 30 -input_format yuyv422 -i /dev/video7 -f alsa -i hw:0,0 -map 0:0 -map 1:0 -b:v 120k -bufsize 120k -vcodec libx264 -preset ultrafast -crf 28 -acodec aac -strict -2 -f flv -metadata streamName= StreamName tcp://71.192.1.22
And this is the subprocess I'm using in Python:
subprocess.Popen("sudo ./ffmpeg_script.sh", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-
ffmpeg cannot recognize the '-af' option
12 novembre 2014, par WangThe ffmpeg cannot recognize the '-af' option. How can I fix this?
$ ffmpeg -i 01.wav -af pan=1:c0=c1 01mono.wav ffmpeg version 0.10.12-7:0.10.12-1~precise1 Copyright (c) 2000-2014 the FFmpeg developers built on Apr 26 2014 09:49:36 with gcc 4.6.3 configuration: --arch=amd64 --disable-stripping --enable-pthreads --enable-runtime-cpudetect --extra-version='7:0.10.12-1~precise1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-libcdio --enable-x11grab --enable-libx264 --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static libavutil 51. 35.100 / 51. 35.100 libavcodec 53. 61.100 / 53. 61.100 libavformat 53. 32.100 / 53. 32.100 libavdevice 53. 4.100 / 53. 4.100 libavfilter 2. 61.100 / 2. 61.100 libswscale 2. 1.100 / 2. 1.100 libswresample 0. 6.100 / 0. 6.100 libpostproc 52. 0.100 / 52. 0.100 [wav @ 0x19dd680] max_analyze_duration 5000000 reached at 5015510 Input #0, wav, from '01.wav': Duration: 00:40:20.40, bitrate: 1411 kb/s Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s Unrecognized option 'af' Failed to set value 'pan=1:c0=c1' for option 'af'
-
Piped FFMPEG won't write frames correctly
12 novembre 2014, par user3180253I am using Python's Image module to load JPEGs and modify them. After I have a modified image, I want to load that image in to a video, using more modified images as frames in my video.
I have 3 programs written to do this: ImEdit (My image editing module that I wrote) VideoWriter (writes to an mp4 file using FFMPEG) and VideoMaker (The file I'm using to do everything)
My VideoWriter looks like this...
import subprocess as sp import os import Image FFMPEG_BIN = "ffmpeg" class VideoWriter(): def __init__(self,xsize=480,ysize=360,FPS=29, outDir=None,outFile=None): if outDir is None: print("No specified output directory. Using default.") outDir = "./VideoOut" if outFile is None: print("No specified output file. Setting temporary.") outFile = "temp.mp4" if (outDir and outFile) is True: if os.path.exists(outDir+outFile): print("File path",outDir+outFile, "already exists:", "change output filename or", "overwriting will occur.") self.outDir = outDir self.outFile = outFile self.xsize,self.ysize,self.FPS = xsize,ysize,FPS self.buildWriter() def setOutFile(self,fileName): self.outFile = filename def setOutDir(self,dirName): self.outDir = dirName def buildWriter(self): commandWriter = [FFMPEG_BIN, '-y', '-f', 'rawvideo', '-vcodec','mjpeg', '-s', '480x360',#.format(480, '-i', '-', '-an', #No audio '-r', str(29), './{}//{}'.format(self.outDir,self.outFile)] self.pW = sp.Popen(commandWriter, stdin = sp.PIPE) def writeFrame(self,ImEditObj): stringData = ImEditObj.getIm().tostring() im = Image.fromstring("RGB",(309,424),stringData) im.save(self.pW.stdin, "JPEG") self.pW.stdin.flush() def finish(self): self.pW.communicate() self.pW.stdin.close()
ImEditObj.getIm() returns an instance of a Python Image object
This code works to the extent that I can load one frame in to the video and no matter how many more calls to writeFrame that I do, the video only every ends up being one frame long. I have other code that works as far as making a video out of single frames and that code is nearly identical to this code. I don't know what difference there is though that makes this code not work as intended where the other code does work.
My question is... How can I modify my VideoWriter class so that I can pass in an instance of an Python's Image object and write that frame to an output file? I also would like to be able to write more than one frame to the video.
I've spent 5 hours or more trying to debug this, having not found anything helpful on the internet, so if I missed any StackOverflow questions that would point me in the right direction, those would be appreciated...
EDIT: After a bit more debugging, the issue may have been that I was trying to write to a file that already existed, however, this doesn't make much sense with the -y flag in my commandWriter. the -y flag should overwrite any file that already exists. Any thoughts on that?