How to detect Audio or Video or Both exist in converted file

Khaja Hussain picture Khaja Hussain · Jul 25, 2013 · Viewed 7.7k times · Source

I am trying to convert mp4 or 3gp video files into Flash (flv) format (using Perl script), using following (mencoder) command:

mencoder test.mp4 -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=1000:mbd=2 -fps 20.80 -ofps 20.80 -oac mp3lame -lameopts abr:br=32 -srate 22050 -o test.flv

It works fine, but some files which comes as attachments from mobile phone has problem, the converted FLV file has only audio.

I also used ffmpeg command as follows:

ffmpeg -i test.mp4 -ar 22050 -acodec libmp3lame -ab 32K -r 25 -vcodec flv test.flv

This ffmpeg command helps to convert to flv, which is failed by mencoder.

I am thinking some solution like, need to check whether converted flv has audio and video then will take action depends on it. Could you help me to solve this issue?

Here is some more info (log):

[mov,mp4,m4a,3gp,3g2,mj2 @ 0xb6b9a3a0]multiple edit list entries, a/v desync might occur, patch welcome ** MUXER_LAVF ************************************* REMEMBER: MEncoder's libavformat muxing is presently broken and can generate INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer will play these INCORRECT files as if nothing were wrong!


Unsupported PixelFormat 61 Unsupported PixelFormat 53 Unsupported PixelFormat 81 [flv @ 0xb6b9a3a0]Codec for stream 0 does not use global headers but container format requires global headers [flv @ 0xb6b9a3a0]Codec for stream 1 does not use global headers but container format requires global headers [flv @ 0xb6b9a3a0]pts < dts in stream 0 Error while writing frame.

[flv @ 0xb6b9a3a0]pts < dts in stream 0 Error while writing frame.

[flv @ 0xb6b9a3a0]pts < dts in stream 0 Error while writing frame.

[flv @ 0xb6b9a3a0]pts < dts in stream 0 Error while writing frame.

[flv @ 0xb6b9a3a0]pts < dts in stream 0 Error while writing frame.

Skipping frame!

.........................

Answer

alexbuisson picture alexbuisson · Jul 26, 2013

A possible solution is to:

  1. use ffmpeg or ffprobe to analyze the output file,

    ffmpeg -i test.flv

a command line output on a file with A/V stream should looks like:

ffmpeg -i test.flv
ffmpeg version N-53818-gfca435f Copyright (c) 2000-2013 the FFmpeg developers
built on Jun  4 2013 01:41:53 with gcc 4.7.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-liray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enabibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enablevpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil      52. 34.100 / 52. 34.100
libavcodec     55. 15.100 / 55. 15.100
libavformat    55.  8.102 / 55.  8.102
libavdevice    55.  2.100 / 55.  2.100
libavfilter     3. 74.101 /  3. 74.101
libswscale      2.  3.100 /  2.  3.100
libswresample   0. 17.102 /  0. 17.102
libpostproc    52.  3.100 / 52.  3.100
Input #0, flv, from 'test.flv':
Metadata:
 starttime       : 0
 totalduration   : 5162
 totaldatarate   : 583
 bytelength      : 376445710
 canseekontime   : true
 sourcedata      : BD075FAE3HH1363450117735644
 purl            :
 pmsg            :
Duration: 01:26:01.70, start: 0.000000, bitrate: 533 kb/s
Stream #0:0: Video: h264 (Main), yuv420p, 640x356, 457 kb/s, 23.98 tbr, 1k tbn, 47.95 tbc
Stream #0:1: Audio: aac, 44100 Hz, stereo, fltp, 131 kb/s
  1. use a regex match to detect if the ffmpeg output contains something like "Stream #.....: Video" AND "Stream #.....: Audio". You can implement and use regular expression in all major shell and languages.

Example:

  "^\s+Stream.+Video." and ^\s+Stream.+Audio.