LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   avconv: convert m4v to avi, but not Avidemux (https://www.linuxquestions.org/questions/linux-software-2/avconv-convert-m4v-to-avi-but-not-avidemux-4175586575/)

Steve W 08-08-2016 11:02 AM

avconv: convert m4v to avi, but not Avidemux
 
If I need to convert an m4v file to avi, I can use Avidemux but it takes a while - about 20-25 mins for a 30 min video on my PC.

I thought I had found a faster method - the shell utility "avconv". However, the files convert faster (takes about 10 mins for a 30 min video), but either the files are 2-3 times as big as the avi's Avidemux produces, or the output is of a lesser quality, depending on the switches I use. It pelts along at around 100-150 frames per second conversion, as opposed to Avidemux's rate of 48-58 fps conversion rate, but with an unsatisfactory result.

I'm sure I'm using the avconv switches wrongly somewhere.

The Avidemux output while converting confirms that the "Quantiser" equals 4; the average bitrate is 800 kb/s. Frames per second conversion rate is around 48 to 58 on average.

By contrast, the avconv script I'm using says:

Code:

for i in *.m4v; do
    avconv -i "$i" -c:v mpeg4 -vtag xvid -c:a libmp3lame -r 30 -b:v 800k "${i%.*}".avi
done

Using this script, the file is an acceptable size, but image frame quality is less. If I use -b:v 1800k or possibly -qscale 4, quality is better but file size shoots up. (I assume qscale is equivalent to Avidemux's quantiser reading).

Also for some reason, while avconv is working away, it states a video bitrate way above the 800k I specify. I am aware that qscale maintains a standard quality regardless of bitrate; but should I be using -b:v to set the bitrate, or qscale to keep the image quality constant?

And what is Avidemux doing that is slower, produces smaller file sizes but still maintains quality?

I did read that Avidemux uses ffmpeg "underneath the hood". But I thought avconv had superseded ffmpeg now. Should I be running a similar script, but using ffmpeg instead of avconv?

Thank you for any help you can give. If I can get avconv producing identical output quality to Avidemux, but 3 times faster, that would be the ideal solution. I could understand avconv producing lower quality output, but faster; but it still only takes 10 mins to produce identical quality output to Avidemux - but with 3 times the file size!

Steve

ondoho 08-08-2016 03:38 PM

Quote:

Originally Posted by Steve W (Post 5587881)
I can use Avidemux but it takes a while - about 20-25 mins for a 30 min video on my PC.

I thought I had found a faster method - the shell utility "avconv". However, the files convert faster (takes about 10 mins for a 30 min video), but either the files are 2-3 times as big as the avi's Avidemux produces, or the output is of a lesser quality, depending on the switches I use.

and that is how it is.
quick conversion = either low quality or huge files
slow conversion = possible to find good balance between quality and filesize.
if you find the right settings for avconv, it will take about as long as with avidemux, i guess. but try by all means, maybe you can shave off some seconds or megabytes.

notKlaatu 08-08-2016 04:00 PM

Avconv "superseded" ffmpeg only according to avconv, and for a while, Debian (although, thankfully, they seem to be backing away from symlinking ffmpeg to avconv as if ffmpeg no longer exists). FFmpeg is still very much alive, still very active, and very relevant.

You probably do want a variable bitrate (VBR). This allows your video converter (ffmpeg or a fork like avconv) to "spend" more bits on complex motion and fewer bits on slow, non-moving (or low motion) shots. `-qscale` is the option for that.

You will also benefit from using the 2-pass option; the first pass allows ffmpeg (or avconv) to calculate bitrates and then the second pass performs the actual encode:

For the first pass, send the output to dev/null:

Code:

$ ffmpeg -i blah.m4v -c:v libxvid -c:a libmp3lame -r 30 -threads 12 -pass 1 -f rawvideo -y /dev/null
This produces no video, but a file called `ffmpeg2pass` is saved in the current directory.

Use this file to help with the second pass:

Code:

$ ffmpeg -i blah.m4v -c:v libxvid -c:a libmp3lame -r 30 -ar 44100 -b:a 128k -qscale 1 -threads 12 -pass 2 -passlogfile ffmpeg2pass foo.avi
Hope that helps. I prefer ffmpeg, so that's what my answers were based on, but all of that ought to translate to avconv.

A lot more about ffmpeg can be read on my site: http://slackermedia.ml/handbook/doku.php?id=ffmpeg

Steve W 08-12-2016 04:29 AM

Okay, thanks for the advice. I might stick with Avidemux then, if it's a swings-and-roundabouts situation. I also notice, when I do "avconv -i [filename]" to get info on a file, the ones from Avidemux use Advanced Simple Profile, but avconv output uses just "Simple Profile". Maybe that also has something to do with it.

Thanks again.

Steve

Emerson 08-12-2016 06:47 AM

You are actually converting H.264 to Xvid. I wonder if there is a simpler solution. Why you need to use AVI container? Will simply remuxing existing video and audio into AVI container work for you?

Steve W 08-13-2016 03:50 AM

Quote:

Why you need to use AVI container? Will simply remuxing existing video and audio into AVI container work for you?
Well, how does that actually work, either in Avidemux or avconv/ffmpeg? Are you saying that in Avidemux I could just change the "Container" dropdown near the bottom of the screen to AVI, leave the other options to just "Copy" and that would work?

I'm trying to make the videos compatible with my DVD player, which has a USB port on the front to play content on a memory stick, but is fussy and does not want to play MP4 or MKV files, only DIVX or XVID files with an AVI extension.

Doing "ffmpeg -i old_video.mp4 -vcodec copy -acodec copy new_video.avi" does not work; it doesn't even preserve audio when I play it back in VLC on my PC!

Neither does using Avidemux as described in my first paragraph above. I cannot see how merely changing the container is going to fool my DVD player into playing a codec it isn't programmed to understand.

Am I doing something wrong? Is it possible your "quick method" you describe could ever work for me?

Emerson 08-13-2016 03:58 AM

I was just wondering. H.264 is MPEG-4 Part 10 coder, while Xvid is MPEG-4 Part 2 codec. They both are MPEG-4, although I'm not sure if AVI container can even handle H.264. It seems your hardware player cannot play it, either. Unfortunately, this means you need to re-code. :(

Edit: https://en.wikipedia.org/wiki/MPEG-4#MPEG-4_Parts

Edit 2: How about retiring this player and replacing it with RPi running OpenElec.

teckk 08-13-2016 09:10 AM

Quote:

I'm trying to make the videos compatible with my DVD player
I don't know what your DVD player is capable of.
DVD standard is mpeg2 video and aac or uncompressed audio. Same as atsc tv signals.

Quote:

I'm not sure if AVI container can even handle H.264.
Yes, you can put 264 and aac or ac3 into an avi. I do it all the time. I would be surprised if a DVD player could play and .avi though.

I don't think that you have said what the audio and video of the original is.
Code:

ffprobe myfile.m4v
https://en.wikipedia.org/wiki/M4V says it is h264 and aac, assuming that it isn't DRM protected.
Code:

ffmpeg -i myfile.m4v -c:a copy -c:v mpeg2video -b:v 2500k output.avi
That will give you (Did a test on a mpeg4 that I had to mpeg2)
Code:

ffprobe output.avi
.......
 Duration: 00:00:51.59, start: 0.000000, bitrate: 2660 kb/s
    Stream #0:0: Video: mpeg2video (Main) (mpg2 / 0x3267706D), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], 2538 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc
    Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 44100 Hz, stereo, fltp, 112 kb/s

DVD standard is also 30 fps, you may have to change that, if it's 24 fps you may need to add frames. (See https://en.wikipedia.org/wiki/Telecine)

I would say that would be your best bet. Make the video conform to DVD standard.

Emerson 08-13-2016 09:35 AM

Quote:

DVD standard is mpeg2 video and aac or uncompressed audio. Same as atsc tv signals.
It is MPEG-2 video and AC-3 or (so called) MP2 audio. I've never seen uncompressed audio in DVD's or broadcast.

teckk 08-13-2016 04:42 PM

I've seen a DVD from a service that ends with flix that had wave audio. I've seen ac3 on DVD's. If you need ac3 audio then:
Code:

ffmpeg -i myfile.m4v -c:a ac3 -b:a 128k -c:v mpeg2video -b:v 2500k output.avi
To the OP, you don't have to use a fixed bitrates. Those were simple examples.
I tried that example and it workid fine.
Code:

ffprobe output.avi
......
 Metadata:
    encoder        : Lavf57.41.100
  Duration: 00:00:33.23, start: 0.000000, bitrate: 2687 kb/s
    Stream #0:0: Video: mpeg2video (Main) (mpg2 / 0x3267706D), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], 2558 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 44100 Hz, stereo, fltp, 128 kb/s

I hadn't recorded an atsc TV stream for a while. So I shoved in a tuner and it is indeed ac3, sorry.
Code:

azap -r -c $HOME/.mplayer/channels.conf WABC
cat /dev/dvb/adapter0/dvr0 > tv1.ts
ffprobe tv1.ts
........
Input #0, mpegts, from 'tv1.ts':
  Duration: 00:00:12.74, start: 11638.308489, bitrate: 10374 kb/s
    Stream #0:0[0x31]: Video: mpeg2video (Main), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 16280 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0x34]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s


Steve W 08-24-2016 02:57 PM

Thank you to everyone for your advice. Think I'll stick with Avidemux for the best overall result then.

Steve


All times are GMT -5. The time now is 06:14 PM.