Answers.Body: <p>The ffprobe command below will spit out the bitrate:</p>
  
  <pre><code>ffprobe in.mp4 -select_streams v -show_entries stream=bit_rate -of compact=p=0:nk=1
  </code></pre>
  
  <p>e.g.</p>
  
  <pre><code>4118620
  </code></pre>
  
  <p>If the result is greater than <code>4000000</code> then you can add <code>-b:v 4000k -bufsize 4000k -maxrate:v 4000k</code>. Or you can add it anyway. Set <code>-c:v</code> to <code>copy</code> if the stream is under <code>4000000</code> else to <code>libx264</code>. The three values will be ignored just like <code>-b:a:0 448k</code> in your command is.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-19T15:04:08.840Z
Answers.Text: Thank you @Mulvya the bit_rate was slightly confusing for me, so I assume bit_rate is bits per second? and 4000000 = 4 Mbps?, I'll test this out and get back asap. The command "-b:a:0 448k" and even "-b:a:1 160k", doesn't get ignored when I run my current script, if I was to output the info, both audio streams display what I set, as for bit_rate, I didn't think of just comparing it to the overall bit_rate, I thought there was more to it than that lol.
Answers.UserDisplayName: Rycore
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-19T16:15:29.287Z
Answers.Text: When `c:a` is set to `copy` for a stream, the `b:a` is inert as there's no encoding being performed.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-21T17:24:53.497Z
Answers.Text: Ah right, I took a look at the files they already had the 448k audio, so it makes sense why it was always the same as my output lol. Just a quick thought and last question lol, can't I just use "-maxrate:v" on its own during the encoding to ensure it doesn't exceed my requirement? or would it be more practical to include "-b:v" and "-buffsize"?
Answers.UserDisplayName: Rycore
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-21T17:32:56.723Z
Answers.Text: If `-b:v` is not set, then the default value (200k) is used, or in the case of x264, CRF mode is used instead of bitrate targeting.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-19T14:01:01.813Z
Answers.LastActivityDate: 2017-01-19T14:01:01.813Z
Answers.UserDisplayName: Gyan
Body: <p>I've been fighting with this dilemma for about a week or two now and I've tried my best to understand it from whatever I can find through google.</p>
  
  <p>What I need (or at least I think I need) to do is calculate the bitrate to determine the mbps, if it's over my requirement (720p @ 4mbps) then I want to optimise the video, if it's below my requirement then it's just a matter of copying the file to an mp4 container.</p>
  
  <p>Now I have my own code for FFmpeg, which I will attach below, and I found that there are alternative applications that will provide me with kbps calculated from the file, but I want to do as much of this as possible with only one application if I can.</p>
  
  <p>I'm not asking anyone to code anything here, but more so to tell me how I can calculate this myself using the information I get from FFmpeg or even FFprobe, and what parameters I'd need to set within FFmpeg to make sure that the video file is encoded to stream at 4mbps.</p>
  
  <pre><code>ffmpeg -i "input.file" -map 0:0 -map 0:1 -map 0:1 -r 30 -profile:v Main -level:v 4.0 -crf 19 -c:a:0 copy -b:a:0 448k -metadata:s:a:0 language="english" -metadata:s:a:0 title="AC3 5.1" -c:a:1 libfdk_aac -ac:a:1 2 -b:a:1 160k -metadata:s:a:1 language="english" -metadata:s:a:1 title="AAC Stereo" -movflags +faststart "output.file"
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Update to my original code</strong></p>
  
  <p>This new code includes the bitrate buffsize and maxrate (if needed), in my script, if the fps is over 30 it will be set to 30, otherwise it was left alone, but if the fps is uncertain, example 23.970542342, this can produce an error in FFmpeg, I thought "-r 23.97" would fix this but apparently not, so I had to change "-r" to "-filter:v fps=" and set the fps for my files by calculating the "r_frame_rate", which is easy enough.</p>
  
  <p>My new code</p>
  
  <pre><code>ffmpeg -i "input.file" -map 0:0 -map 0:1 -map 0:1 -filter:v fps=30 -profile:v Main -level:v 4.0 -crf 18 -b:v 4000k -bufsize 4000k -maxrate:v 4000k -metadata title="" -metadata year="" -c:a:0 copy -metadata:s:a:0 language="english" -metadata:s:a:0 title="AC3 5.1" -c:a:1 libfdk_aac -ac:a:1 2 -b:a:1 160k -metadata:s:a:1 language="english" -metadata:s:a:1 title="AAC Stereo" -movflags +faststart "output.file"
  </code></pre>
  
  <p>In the script that I'm building, it's going to generate the appropriate parameters for FFmpeg, so if the codec is not x264, if profile:v is not main, if level:v is not 4.0, if bit_rate is more than 4000k, then all the needed parameters will be set, otherwise it gets copied.</p>
  
  <p>FFprobe Code from Mulvya, slightly modified so I can get everything I need from it.</p>
  
  <pre><code>ffprobe -v error -select_streams v -show_entries stream="bit_rate,codec_name,profile,level,r_frame_rate" -of compact=p=0:nk=1 "input.file"
  </code></pre>
  
  <p>Goal at the end of this is to have my own automation script to encode my videos from a folder, I know about sickbeard mp4 automator, but I don't need all those features, and there are things I want that it doesn't have.</p>
  
Tags: <ffmpeg><encoding><mp4><bitrate>
Title: FFmpeg, encode video for 720p @ 4mbps playback
UserDisplayName: Rycore
ThreadText: # FFmpeg, encode video for 720p @ 4mbps playback
  
  (Asked by: username_0 on 2017-01-19)
  
  I've been fighting with this dilemma for about a week or two now and I've tried my best to understand it from whatever I can find through google.
  
  What I need (or at least I think I need) to do is calculate the bitrate to determine the mbps, if it's over my requirement (720p @ 4mbps) then I want to optimise the video, if it's below my requirement then it's just a matter of copying the file to an mp4 container.
  
  Now I have my own code for FFmpeg, which I will attach below, and I found that there are alternative applications that will provide me with kbps calculated from the file, but I want to do as much of this as possible with only one application if I can.
  
  I'm not asking anyone to code anything here, but more so to tell me how I can calculate this myself using the information I get from FFmpeg or even FFprobe, and what parameters I'd need to set within FFmpeg to make sure that the video file is encoded to stream at 4mbps.
  
  ```
  ffmpeg -i "input.file" -map 0:0 -map 0:1 -map 0:1 -r 30 -profile:v Main -level:v 4.0 -crf 19 -c:a:0 copy -b:a:0 448k -metadata:s:a:0 language="english" -metadata:s:a:0 title="AC3 5.1" -c:a:1 libfdk_aac -ac:a:1 2 -b:a:1 160k -metadata:s:a:1 language="english" -metadata:s:a:1 title="AAC Stereo" -movflags +faststart "output.file"
  
  ```
  
  Thanks in advance.
  
  **Update to my original code**
  
  This new code includes the bitrate buffsize and maxrate (if needed), in my script, if the fps is over 30 it will be set to 30, otherwise it was left alone, but if the fps is uncertain, example 23.970542342, this can produce an error in FFmpeg, I thought "-r 23.97" would fix this but apparently not, so I had to change "-r" to "-filter:v fps=" and set the fps for my files by calculating the "r\_frame\_rate", which is easy enough.
  
  My new code
  
  ```
  ffmpeg -i "input.file" -map 0:0 -map 0:1 -map 0:1 -filter:v fps=30 -profile:v Main -level:v 4.0 -crf 18 -b:v 4000k -bufsize 4000k -maxrate:v 4000k -metadata title="" -metadata year="" -c:a:0 copy -metadata:s:a:0 language="english" -metadata:s:a:0 title="AC3 5.1" -c:a:1 libfdk_aac -ac:a:1 2 -b:a:1 160k -metadata:s:a:1 language="english" -metadata:s:a:1 title="AAC Stereo" -movflags +faststart "output.file"
  
  ```
  
  In the script that I'm building, it's going to generate the appropriate parameters for FFmpeg, so if the codec is not x264, if profile:v is not main, if level:v is not 4.0, if bit\_rate is more than 4000k, then all the needed parameters will be set, otherwise it gets copied.
  
  FFprobe Code from Mulvya, slightly modified so I can get everything I need from it.
  
  ```
  ffprobe -v error -select_streams v -show_entries stream="bit_rate,codec_name,profile,level,r_frame_rate" -of compact=p=0:nk=1 "input.file"
  
  ```
  
  Goal at the end of this is to have my own automation script to encode my videos from a folder, I know about sickbeard mp4 automator, but I don't need all those features, and there are things I want that it doesn't have.
  
  **Tags:** ffmpeg, encoding, mp4, bitrate
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-19. Score: 1 | Accepted answer
  
  The ffprobe command below will spit out the bitrate:
  
  ```
  ffprobe in.mp4 -select_streams v -show_entries stream=bit_rate -of compact=p=0:nk=1
  
  ```
  
  e.g.
  
  ```
  4118620
  
  ```
  
  If the result is greater than `4000000` then you can add `-b:v 4000k -bufsize 4000k -maxrate:v 4000k`. Or you can add it anyway. Set `-c:v` to `copy` if the stream is under `4000000` else to `libx264`. The three values will be ignored just like `-b:a:0 448k` in your command is.
  
  > **Comments:**
  > **username_0**: Thank you @Mulvya the bit_rate was slightly confusing for me, so I assume bit_rate is bits per second? and 4000000 = 4 Mbps?, I'll test this out and get back asap. The command "-b:a:0 448k" and even "-b:a:1 160k", doesn't get ignored when I run my current script, if I was to output the info, both audio streams display what I set, as for bit_rate, I didn't think of just comparing it to the overall bit_rate, I thought there was more to it than that lol.  
  > **username_1**: When `c:a` is set to `copy` for a stream, the `b:a` is inert as there's no encoding being performed.  
  > **username_0**: Ah right, I took a look at the files they already had the 448k audio, so it makes sense why it was always the same as my output lol. Just a quick thought and last question lol, can't I just use "-maxrate:v" on its own during the encoding to ensure it doesn't exceed my requirement? or would it be more practical to include "-b:v" and "-buffsize"?  
  > **username_1**: If `-b:v` is not set, then the default value (200k) is used, or in the case of x264, CRF mode is used instead of bitrate targeting.  
  
  ---
  
  