LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Converting flv to Mpg with Audio and ffmpeg (https://www.linuxquestions.org/questions/linux-software-2/converting-flv-to-mpg-with-audio-and-ffmpeg-646876/)

btbx 06-04-2008 02:20 AM

Converting flv to Mpg with Audio and ffmpeg
 
I try to conver flv files to ordinary mpg with ffmpeg.
I try many audio options including bitrate, sampling, audio channel,
but the result is no audio at all / silent.
The picture is OK

What is the best software for converting flv movies to mpg?

What is the best parameter for ffmpeg that will work 100%?

Thank you.

David the H. 06-04-2008 07:28 AM

There is no 100% solution when it comes to multimedia because there are too many variables to consider. What may work on one file can easily fail on another with only slightly different parameters.

At a first guess, I'd say it's probably a codec problem. You may need to install a separate audio decoder or get/recompile a version of ffmpeg with different codec support. Try running "ffplay file.flv" to see if ffmpeg can decode file normally.

Anyway, how about showing us the command(s) you've tried and what output you get. And is this true of all flv files or just a few? Have you tried the same processes on other types of files such as an avi or mpeg?

dracolich 06-04-2008 04:20 PM

I have a script I found to convert flv to avi. When I first tried it I missed the avifix command and was getting the same result of video without audio. You could probably use this and modify or add to it to change the avi to mpg. Hope this helps.

Code:

#!/bin/sh

if [ $# = 0 ]; then
echo "Usage: flv2avi file.flv"
exit 1
fi

#Convert to avi with stereo 48K sound
OUT=$1.avi
ffmpeg  -i $1 -ar 48000 -ac 2 $OUT
avifix -i $OUT -F DX50

exit 1


btbx 06-05-2008 12:47 AM

Thank you for all answers.

All example online from google use ffmpeg with kbits as parameter, not bits with erronous result.

example ffmpeg -ab 56, when it should be ffmpeg -ab 56000

I had created a general purpose 1 line script:

Content flv2mpg.sh

ffmpeg -i $1.flv -ab 128000 -ar 44100 -b 500000 -s 640x480 -ac 2 -acodec libmp3lame $1.mpg


-ab parameter: audio bitrate. Other: 56000, 80000, 256000
-ar parameter: audio sampling rate (Hz). Other: 22050
-b parameter: bitrate: 500000: high bitrate may reduce "Pixelated" effect".
-s parameter: screen resolution. Other: 320x200
-ac parameter: number of audio channel. Other: 1 (mono)
2 (stereo).
-acodec parameter: audio codec.

Before using the script make sure ffmpeg is compiled with built-in libmp3lame. You must install / compile lame first before compiling ffmpeg.

Present problems:
File name after -i cannot contain space or "-" (minus) character. Example:

flv2mpg "Lionel Richie---Hello.flv" will produce error.
I had to rename the file to "richiehello.flv"
After the conversion I had to rename the result from
"richiehello.mpg" to "Lionel Richie---Hello.mpg"

Is it possible to modify the script to enable it to accept space and "-" (minus) character?

Thank you.

David the H. 06-05-2008 02:26 AM

About a year or so ago the ffmpeg project changed their command argument requirements a bit, and one of the things they changed was to require -b and -ab to be in bits. This is why most older examples are wrong. You can easily fix them by simply adding 'k' to the bitrate numbers; e.g. "-b 48k".

But now I don't understand. Your second post has nothing to do with the problem you expressed in the first. Did you manage to get the audio working? Was it just because of the inaccurate bitrate problem?

As for your script, you have to put quotes around the whole filename in order to ensure that it is read as a unit. This is true for the command line and also true for any $# outputs in the script itself. So simply put quotes around the "$1" entries.

Code:

#!/bin/bash

ffmpeg -i "$1".flv -ab 128000 -ar 44100 -b 200000 -s 640x480 -ac 2 -acodec libmp3lame "$1".mpg

That should let it work. Though to tell the truth, it's good practice to avoid spaces and illegal characters in filenames anyway. They're such a headache to work around. I personally try to keep most of my files in lower-case, with spaces changed to underscores and odd characters kept to a minimum. It saves me a lot of hassle that way.

btbx 06-06-2008 06:48 AM

Thank you for the explanation and correction.

I found another flv to mpg converter script on google using mencoder.

Unfortunately I cannot find the correct parameter.

The audio stutter (stop and go) and cannot be used at all.
The video is OK.

Any idea how to use mencoder for converting flv to mpg?
Thank you.

btbx 06-07-2008 06:37 PM

After several days of battle with mencoder parameters, I created 2 reliable scripts in turning flv videos to mpg with libmp3lame (mp3) and flv to avi with twolame (mp2).

Is there any other possible correction / improvement of the script?
The stuttering audio (stop and go) is because the default bit rate is too high. I use 64 and 56.

Content of flv2mpg script:

mencoder "$1" -mc 0 -noskip -vf harddup -oac lavc -lavcopts acodec=libmp3lame:abitrate=64 -ovc lavc -o "$1".mpg

Content of flv2avi script:

mencoder "$1" -mc 0 -noskip -vf harddup -oac twolame -twolameopts br=56 -ovc lavc -o "$1".avi

btbx 06-12-2008 02:41 PM

The above script flv2mpg.sh produce file with FMP4 (MPEG4 ISO / DIVX 5) standard codec.

Unfortunately some media player device, picture frame that support MP4 actually use
older standards of MPEG4: mspeg4 or msmpeg4v2.

To create video file with old standard:

flv2oldmpeg4.sh

mencoder "$1" -mc 0 -noskip -vf harddup -oac mp3lame -lameopts preset=64:mode=0:vol=10:cbr -ovc lavc -lavcopts vcodec=msmpeg4v2:vpass=1 -o "$1".mpg

...Or....

mencoder "$1" -mc 0 -noskip -vf harddup -oac mp3lame -lameopts preset=64:mode=0:vol=10:cbr -ovc lavc -lavcopts vcodec=msmpeg4:vpass=1 -o "$1".mpg

Audio setting: 64 bit constant bit rate, with 10 volume gain and stereo mode.


All times are GMT -5. The time now is 08:23 PM.