ampache / ampache

A web based audio/video streaming application and file manager allowing you to access your music & videos from anywhere, using almost any internet enabled device.
http://ampache.org
GNU Affero General Public License v3.0
3.54k stars 588 forks source link

transcoding problem #961

Closed ufp32633 closed 8 years ago

ufp32633 commented 9 years ago

Probably this is not the place to ask, but I can't find a better place.

I don't understand the logic behind the transcoding function. In the config I've set transcode_flac = required I don't want to stream flac directly. The sound quality is good but it stops regularly for a brief moment when Ampache decides to reload, so I want to stream it as mp3.

I know I can convert flac to mp3 using this command: avconv -i "input filename here" -c:a libmp3lame -b:a 320k "output filename here" as far as I can understand the config this apparently translates to:

encode_args_flac = "-c:a libmp3lame -b:a 320k -f mp3 pipe:1" I use 320k because I like 320kb streams and my server can handle it. I don't know what the pipe:1 part is about, but it is in all commands so apparently it is necessary.

If I try this something is definitely happening because the sound quality has now changed to terrible while regular mp3's still sound good. So there must be something wrong with the command.

The general info about Ampache on the internet is rather outdated on all sites I could find. Can someone please give some advise?

Psy-Virus commented 9 years ago

Hey @ufp32633,

you need to set the bit rate within the GUI, under the user- and/or under the server preferences in the streaming section. Depending on your wishes, if the 320kbit/s should only be set for you or globally or both.

Screeny:

tmp_bitrate

The pipe:1 is the output that Ampache/PHP uses for streaming.

Simplified: FLAC-file -> avconv -> mp3-file/stream -> pipe:1 -> Ampache/PHP -> You

If you use this in your config: encode_args_mp3 = "-vn -b:a %SAMPLE%K -c:a libmp3lame -f mp3 pipe:1"

it should work for you

:-)

Psy-Virus commented 9 years ago

That way it should convert your FLAC-file with your source (FLAC-)file's Sample-Rate (for example: 44.1kHz), the Bit Rate you set (160, or in your case 320kbit/s) and the lame mp3 codec.

@Afterster, I think the %SAMPLE% variable isn't well named. It's the bit rate and not the sample rate.

And as far as I see it, Ampache/avconv does not a downsampling. It's more a compression. A downsampling would it be if the sample rate would be reduced from for example: 48kHz to 44.1kHz

A conversion of the bit rate (from high to low) is a compression, because the higher and lower frequencies (some bad guys say "the unnecessary/unhearable") frequencies are killed to reach a smaller amount of information and smaller files.

ufp32633 commented 9 years ago

Hi, @Psy-Virus,

Awesome, that did the trick. Thanks so much!

You advised me to use: encode_args_mp3 = "-vn -b:a %SAMPLE%K -c:a libmp3lame -f mp3 pipe:1" since that line is already in the config I've changed it too: encode_args_flac = "-vn -b:a %SAMPLE%K -c:a libmp3lame -f mp3 pipe:1" because we were talking about flac. I've tested this with a track of synthesizer music and apart from one small hiccup in the beginning of the track it plays very well. Probably I've to revise the 320 kbit setting a little bit.

With regard to your previous comment: I wasn't confused by the %sample% variable because I couldn't find it in the source code therefore I hardcoded 320 in the encoding arguments. I was confused by something else. In the streaming section under server preferences my English version says: 'Transcode Bitrate'. I thought this referred to the output bitdepth which is typically 16bit, 24bit (CD quality) or 32bit (high quality). So I had it set to 32. This explains why the sound quality was terrible because it was set to be terrible :-) In your screenshot I can tell from the German translation what the setting really means.

That being said: I already changed from Dutch to English because the Dutch translation is inaccurate and/or incomplete. Apparently even the English translation isn't complete because your version says ("Rate Limit" * 1024) in the 5th option in your screenshot while the English version omits this explanation.

Can I offer some help in creating or modifying a Dutch translation and/or Dutch material in general?

Psy-Virus commented 9 years ago

Can I offer some help in creating or modifying a Dutch translation and/or Dutch material in general?

Yes sure, you're definitely welcome to translate Ampache! :-) Simply join us on Transifex and start translating^^. It should be really that simple, but if you have questions that the TRANSLATIONS.md can't answer, simply ask on Transifex itself or on Googlegroups. :-)

You advised me to use: encode_args_mp3 = "-vn -b:a %SAMPLE%K -c:a libmp3lame -f mp3 pipe:1" since that line is already in the config I've changed it too: encode_args_flac = "-vn -b:a %SAMPLE%K -c:a libmp3lame -f mp3 pipe:1" because we were talking about flac.

The encode_args_XXX are for the outputs, the inputs are handled by avconv itself. ;-)

That being said: I already changed from Dutch to English because the Dutch translation is inaccurate and/or incomplete. Apparently even the English translation isn't complete because your version says ("Rate Limit" * 1024) in the 5th option in your screenshot while the English version omits this explanation.

That's why I want to rewrite the English/Source sentences. But I still wait for the "go" from @SUTJael.

I wasn't confused by the %sample% variable because I couldn't find it in the source code therefore I hardcoded 320 in the encoding arguments. I was confused by something else.

This explanation was more meant for Afterster

In the streaming section under server preferences my English version says: 'Transcode Bitrate'. I thought this referred to the output bitdepth which is typically 16bit, 24bit (CD quality) or 32bit (high quality). So I had it set to 32.

Maybe we also should think about adding the bit depths as convert option... (AAAAAA @Afterster ... hehe... How are your thoughts?)

This explains why the sound quality was terrible because it was set to be terrible :-)

Sure, hehe^^

SUTJael commented 9 years ago

Could be closed? :)

ufp32633 commented 9 years ago

Since my initial question is answered, I guess yes. However during the conversation a few new interesting thoughts have surfaced which may be worth some discussion, so I'm not going to close the question myself instead I'll keep an eye on it to see if something interesting happens.

I'll take this opportunity to say thanks to you all for sharing useful information.

ufp32633 commented 9 years ago

Wait, don't close it please. Now I'm uncertain what's happening. On further inspection I saw I had transcode_flac = required commented out in the config so I guess it was streaming flac altogether. I've uncommented transcode_flac = required and that results in complete silence. Ampache says it is playing but it is not in the webplayer. If I set transcode_flac = allowed there's sound in the webplayer but I've the impression that it is just streaming flac again instead of the transcoded mp3 because the sound quality is really good.

Sorry, probably I'm asking for the obvious here but I need more info. What do the options allowed, required and false mean? Or stated differently: what do I need to set in order to get flac transcoded to mp3 in the webplayer. The transcode command is already correct based on the advice given by @Psy-Virus. I feel as if I almost need to be a soundengineer to be able to understand this ;-)

Psy-Virus commented 9 years ago

I'll take this opportunity to say thanks to you all for sharing useful information.

Yey I AM LEGION :D :D :D

Okay... where should I begin... (EDIT: It's quite long... happy reading ;-) )

As it is written, it's the Input type selection or section.

Everything that is allowed, > can < be converted or transcoded. Everything that is required, > will definitely < be converted or transcoded and Everything that is set to false, > wont < be converted.

This settings are related to the following GUI user setting under streaming: (dropdown menu from top to bottom (never, standard, ever))

tmpstreaming

(the following is based on my memory ~2 years ago so >maybe< it isn't completely right, but it will help you anyway)

False means, every file will be streamed as they are. Flacs will be streamed as flacs, mp3s as mp3s and so on.

standard means, every file is converted like it is set in your config. You need to configure:

ever means, that everything is converted or transcoded to the encode_target regardless what you've set within the input type selection.

Last but not least, here is my config (the transcode part audio/video) as example for you: This config is mostly standard. I only have changed it that way, that all audio is converted to mp3 and all video is converted to webm. But there's one difference. webm source files wont be converted but mp3 source files above 160kbit/s (192kbit/s, 320kbit/s) will be compressed/converted to 160kbit/s, as it is set within the GUI (screeny)

;########################################################
; These options control the dynamic downsampling based  #
; on current usage                                      #
; *Note* Transcoding must be enabled and working        #
;########################################################

; Attempt to optimize bandwidth by dynamically lowering the bit rate of new
; streams. Since the bit rate is only adjusted at the beginning of a song, the
; actual cumulative bitrate for concurrent streams can be up to around
; double the configured value. It also only applies to streams that are
; transcoded.
; DEFAULT: none
;max_bit_rate = 576

; New dynamically downsampled streams will be denied if they are forced below
; this value.
; DEFAULT: 8
;min_bit_rate = 48

;######################################################
; These are commands used to transcode non-streaming
; formats to the target file type for streaming.
; This can be useful in re-encoding file types that don't stream
; very well, or if your player doesn't support some file types.
;
; 'Downsampling' will also use these commands.
;
; To state the bleeding obvious, any programs referenced in the transcode
; commands must be installed, in the web server's search path (or referenced
; by their full path), and executable by the web server.

; Input type selection
; TYPE is the extension. 'allowed' certifies that transcoding works properly for
; this input format. 'required' further forbids the direct streaming of a format
; (e.g. if you store everything in FLAC, but don't want to ever stream that.)
; transcode_TYPE         = {allowed|required|false}
; DEFAULT: false
;;; Audio
transcode_m4a = "required"
transcode_flac = "required"
transcode_mpc = "required"
transcode_ogg = "required"
transcode_oga = "required"
transcode_wav = "required"
transcode_wma = "required"
transcode_aif = "required"
transcode_aiff = "required"
transcode_ape = "required"
transcode_shn = "required"
transcode_mp3 = "allowed"
;;; Video
transcode_avi = "required"
transcode_mkv = "required"
transcode_mpg = "required"
transcode_mpeg = "required"
transcode_m4v = "required"
transcode_mp4 = "required"
transcode_mov = "required"
transcode_wmv = "required"
transcode_ogv = "required"
transcode_divx = "required"
transcode_m2ts = "required"
transcode_webm = "false"

; Default audio output format
; DEFAULT: none
encode_target = "mp3"

; Default video output format
; DEFAULT: none
encode_video_target = "flv"

; Override the default output format on a per-type basis
; encode_target_TYPE = TYPE
; DEFAULT: none
;encode_target_flac = ogg

; Override the default TYPE transcoding behavior on a per-player basis
; transcode_player_PLAYER_TYPE = TYPE
; Valid PLAYER is: webplayer, api
; DEFAULT: none
;transcode_player_webplayer_m4a = required
;transcode_player_webplayer_flac = required
;transcode_player_webplayer_mpc = required

; Override the default output format on a per-player basis
; encode_player_PLAYER_target = TYPE
; Valid PLAYER is: webplayer, api
; DEFAULT: none
;encode_player_webplayer_target = mp3
;encode_player_api_target = mp3

; Allow clients to override transcode settings (output type, bitrate, codec ...)
; DEFAULT: true
transcode_player_customize = "true"

; Command configuration. Substitutions will be made as follows:
; %FILE% => filename
; %SAMPLE% => target sample rate
; You can do fancy things like VBR, but consider whether the consequences are
; acceptable in your environment.

; Master transcode command
; transcode_cmd should be a single command that supports multiple file types,
; such as ffmpeg or avconv. It's still possible to make a configuration that's
; equivalent to the old default, but if you find that necessary you should be
; clever enough to figure out how on your own.
; DEFAULT: none
;transcode_cmd = "ffmpeg"
transcode_cmd = "avconv"
;transcode_cmd = "/usr/bin/neatokeen"

; Transcode input file argument
transcode_input = "-i %FILE%"

; Specific transcode commands
; It shouldn't be necessary in most cases, but you can override the transcode
; command for specific source formats.  It still needs to accept the
; encoding arguments, so the easiest approach is to use your normal command as
; a clearing-house.
; transcode_cmd_TYPE = TRANSCODE_CMD
;transcode_cmd_mid = "timidity -Or -o – %FILE% | ffmpeg -f s16le -i pipe:0"

; Encoding arguments
; For each output format, you should provide the necessary arguments for
; your transcode_cmd.
; encode_args_TYPE = TRANSCODE_CMD_ARGS
encode_args_mp3 = "-vn -b:a %SAMPLE%K -c:a libmp3lame -f mp3 pipe:1"
encode_args_ogg = "-vn -b:a %SAMPLE%K -c:a libvorbis -f ogg pipe:1"
encode_args_m4a = "-vn -b:a %SAMPLE%K -c:a libfdk_aac -f adts pipe:1"
encode_args_wav = "-vn -b:a %SAMPLE%K -c:a pcm_s16le -f wav pipe:1"
encode_args_flv = "-b:a %SAMPLE%K -ar 44100 -ac 2 -v 0 -f flv -c:v libx264 -preset superfast -threads 0 pipe:1"
encode_args_webm = "-q %QUALITY% -f webm -c:v libvpx -maxrate %MAXBITRATE%k -preset superfast -threads 0 pipe:1"
encode_args_ts = "-q %QUALITY% -s %RESOLUTION% -f mpegts -c:v libx264 -c:a libmp3lame -maxrate %MAXBITRATE%k -preset superfast -threads 0 pipe:1"

; Encoding arguments to retrieve an image from a single frame
encode_get_image = "-ss %TIME% -f image2 -vframes 1 pipe:1"

; Encoding argument to encrust subtitle
encode_srt = "-vf \"subtitles='%SRTFILE%'\""

; Encode segment frame argument
encode_ss_frame = "-ss %TIME%"

; Encode segment duration argument
encode_ss_duration = "-t %DURATION%"

I feel as if I almost need to be a soundengineer to be able to understand this ;-)

:D No you don't, but you definitely need at least the basics^^ ... oh.. and time, hehe.