Advertisement
thioshp

FFmpeg: Converting M4A Files to MP3 With the Same Bitrate

May 14th, 2016
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. 1. Get M4A File's Details
  2. By using the command "ffmpeg -i" the file we obtain data about all streams of the file (codec, bitrate, ...), like this:
  3.  
  4. $ ffmpeg -i test.m4a
  5. [...]
  6. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.m4a':
  7. Metadata:
  8. major_brand : M4A
  9. minor_version : 1
  10. compatible_brands: M4A mp42isom
  11. creation_time : 2012-01-06 13:08:47
  12. composer : Tiësto
  13. title : clublife_episode249
  14. artist : Tiësto
  15. album : Tiësto
  16. encoder : GarageBand 6.0.4
  17. Duration: 00:59:04.87, start: 0.000000, bitrate: 324 kb/s
  18. Chapter #0.0: start 0.000000, end 31.000000
  19. Metadata:
  20. title : Begin
  21. [...]
  22. Stream #0.0(eng): Subtitle: tx3g / 0x67337874, 0 kb/s
  23. Metadata:
  24. creation_time : 2012-01-06 13:08:47
  25. Stream #0.1(eng): Subtitle: tx3g / 0x67337874
  26. Metadata:
  27. creation_time : 2012-01-06 13:08:47
  28. Stream #0.2(eng): Audio: aac, 44100 Hz, stereo, s16, 319 kb/s
  29. Metadata:
  30. creation_time : 2012-01-06 13:08:47
  31. Stream #0.3(eng): Video: mjpeg, yuvj444p, 300x300 [PAR 72:72 DAR 1:1], 2 kb/s, 0k fps, 600 tbr, 600 tbn, 600 tbc
  32. Metadata:
  33. creation_time : 2012-01-06 13:08:47
  34.  
  35. Well, the line we need to use for the bitrate is Stream #0.2(eng): Audio: aac, 44100 Hz, stereo, s16, 319 kb/s.
  36.  
  37. 2. Extract M4A File's Audio Bitrate
  38. Now we can play with grep and awk to extract 319 (according to the example line):
  39.  
  40. $ ffmpeg -i test.m4a 2>&1 | grep Audio | awk -F', ' '{print $5}' | cut -d' ' -f1
  41. 319
  42. This output will be used for the -ab argument:
  43.  
  44. 3. Convert M4A to MP3 With Same Bitrate
  45. ffmpeg -i test.m4a -ab `ffmpeg -i test.m4a 2>&1 | grep Audio | awk -F', ' '{print $5}' | cut -d' ' -f1`k test.mp3
  46.  
  47. 4. Verify MP3 File
  48. Finally, we verify the new file:
  49.  
  50. $ ffmpeg -i test.mp3
  51. [...]
  52. Input #0, mp3, from 'test.mp3':
  53. Metadata:
  54. major_brand : M4A
  55. minor_version : 1
  56. compatible_brands: M4A mp42isom
  57. creation_time : 2012-01-06 13:08:47
  58. composer : Tiësto
  59. title : clublife_episode249
  60. artist : Tiësto
  61. album : Tiësto
  62. encoder : Lavf53.2.0
  63. Duration: 00:59:04.93, start: 0.000000, bitrate: 320 kb/s
  64. Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 320 kb/s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement