I'm trying to get familiar with python subprocess and here is my little code:
import subprocess
import os
import re
import subprocess as sp
import logging
the_file = "/home/vagrant/test/out.pkg"
out_file = "/home/vagrant/test/result.mp4"
ffmpeg = sp.Popen(['/usr/bin/ffmpeg', '-i', the_file, out_file], stdout = sp.PIPE, stderr = sp.STDOUT)
process_output = ffmpeg.communicate()
print "communicate:", process_output
The result :
communicate: ("ffmpeg version N-75410-g58fe57d Copyright (c) 2000-2015 the FFmpeg developers\n built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)\n configuration: --prefix=/home/vagrant/ffmpeg_build --extra-cflags=-I/home/vagrant/ffmpeg_build/include --extra-ldflags=-L/home/vagrant/ffmpeg_build/lib --bindir=/usr/local/bin --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libvpx --enable-libx264 --enable-libfreetype\n libavutil 55. 2.100 / 55. 2.100\n libavcodec 57. 3.100 / 57. 3.100\n libavformat 57. 2.100 / 57. 2.100\n libavdevice 57. 0.100 / 57. 0.100\n libavfilter 6. 5.100 / 6. 5.100\n libswscale 4. 0.100 / 4. 0.100\n libswresample 2. 0.100 / 2. 0.100\n libpostproc 54. 0.100 / 54. 0.100\nInput #0, tty, from '/home/vagrant/test/out.txt':\n Duration: 00:00:00.04, bitrate: 1 kb/s\n Stream #0:0: Video: ansi, pal8, 640x400, 25 fps, 25 tbr, 25 tbn, 25 tbc\nNo pixel format specified, yuv444p for H.264 encoding chosen.\nUse -pix_fmt yuv420p for compatibility with outdated media players.\n[libx264 @ 0x379f300] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64\n[libx264 @ 0x379f300] profile High 4:4:4 Predictive, level 3.0, 4:4:4 8-bit\n[libx264 @ 0x379f300] 264 - core 148 r2597 e86f3a1 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00\nOutput #0, mp4, to '/home/vagrant/test/result.mp4':\n Metadata:\n encoder : Lavf57.2.100\n Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 640x400, q=-1--1, 25 fps, 12800 tbn, 25 tbc\n Metadata:\n encoder : Lavc57.3.100 libx264\nStream mapping:\n Stream #0:0 -> #0:0 (ansi (native) -> h264 (libx264))\nPress [q] to stop, [?] for help\nframe= 1 fps=0.0 q=28.0 Lsize= 2kB time=00:00:00.04 bitrate= 362.4kbits/s \nvideo:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 78.698227%\n[libx264 @ 0x379f300] frame I:1 Avg QP:13.08 size: 326\n[libx264 @ 0x379f300] mb I I16..4: 0.4% 99.1% 0.5%\n[libx264 @ 0x379f300] 8x8 transform intra:99.1%\n[libx264 @ 0x379f300] coded y,u,v intra: 0.4% 0.0% 0.0%\n[libx264 @ 0x379f300] i16 v,h,dc,p: 0% 75% 25% 0%\n[libx264 @ 0x379f300] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 0% 92% 8% 0% 0% 0% 0% 0% 0%\n[libx264 @ 0x379f300] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 35% 35% 2% 1% 0% 2% 0% 0%\n[libx264 @ 0x379f300] kb/s:65.20\n", None)
As it expected, sends me back a tuple (stdout,stderr). But the problem is, ffmpeg converts any file(as you can see above, even pkg file) without giving me back an error or exit status with 1. stderr = None
Can anyone explain what's wrong on this one? Thanks so much.